Fawkes API  Fawkes Development Version
fawkes::HungarianMethod Class Reference

Hungarian method assignment solver. More...

#include <>>

Public Member Functions

 HungarianMethod ()
 Constructor. More...
 
 ~HungarianMethod ()
 Destructor. More...
 
int init (int **cost_matrix, int rows, int cols, int mode)
 Initialize hungarian method. More...
 
void free ()
 Free space alloacted by method. More...
 
void solve ()
 Solve the assignment problem. More...
 
bool is_available ()
 Check if data is available. More...
 
int get_column_assignment (const int &col)
 Get column assignment. More...
 
int get_row_assignment (const int &row)
 Get row assignment. More...
 
int * get_assignment (int &size)
 Get assignment and size. More...
 
int ** array_to_matrix (int *m, int rows, int cols)
 Convert an array to a matrix. More...
 
void print_assignment ()
 Print the assignment matrix. More...
 
void print_cost_matrix ()
 Print the cost matrix. More...
 
void print_status ()
 Print the current status. More...
 

Public Attributes

hungarian_problem_t * p
 our problem instance member. More...
 

Protected Member Functions

void print_matrix (int **C, int rows, int cols)
 Print matrix to stdout. More...
 

Detailed Description

Hungarian method assignment solver.

Author
Stefan Schiffer

Definition at line 49 of file hungarian.h.

Constructor & Destructor Documentation

◆ HungarianMethod()

fawkes::HungarianMethod::HungarianMethod ( )

Constructor.

Definition at line 52 of file hungarian.cpp.

References p.

◆ ~HungarianMethod()

fawkes::HungarianMethod::~HungarianMethod ( )

Destructor.

Definition at line 61 of file hungarian.cpp.

References free(), and p.

Member Function Documentation

◆ array_to_matrix()

int ** fawkes::HungarianMethod::array_to_matrix ( int *  m,
int  rows,
int  cols 
)

Convert an array to a matrix.

Parameters
marray to convert
rowsnumber of rows in array
colsnumber of columns in array
Returns
matrix from array

Definition at line 96 of file hungarian.cpp.

◆ free()

void fawkes::HungarianMethod::free ( )

Free space alloacted by method.

Definition at line 225 of file hungarian.cpp.

References p.

Referenced by solve(), and ~HungarianMethod().

◆ get_assignment()

int * fawkes::HungarianMethod::get_assignment ( int &  size)

Get assignment and size.

Parameters
sizenumber of rows/columns in quadratic matrix
Returns
pointer to columns.

Definition at line 592 of file hungarian.cpp.

References p.

Referenced by TabletopObjectsThread::loop().

◆ get_column_assignment()

int fawkes::HungarianMethod::get_column_assignment ( const int &  col)

Get column assignment.

Parameters
colcolumn index
Returns
column assignment, or -1 if col is out of bounds.

Definition at line 552 of file hungarian.cpp.

◆ get_row_assignment()

int fawkes::HungarianMethod::get_row_assignment ( const int &  row)

Get row assignment.

Parameters
rowrow index
Returns
row assignment, or -1 if row is out of bounds.

Definition at line 567 of file hungarian.cpp.

◆ init()

int fawkes::HungarianMethod::init ( int **  cost_matrix,
int  rows,
int  cols,
int  mode 
)

Initialize hungarian method.

Parameters
cost_matrixinitial cost matrix
rowsnumber of rows in matrix
colsnumber of columns in matrix
modeOne of HUNGARIAN_MODE_MINIMIZE_COST and HUNGARIAN_MODE_MAXIMIZE_UTIL
Returns
number of rows in quadratic matrix

Definition at line 148 of file hungarian.cpp.

References p.

Referenced by TabletopObjectsThread::loop().

◆ is_available()

bool fawkes::HungarianMethod::is_available ( )

Check if data is available.

solve done and not freed yet.

Returns
true if data is available, false otherwise

Definition at line 581 of file hungarian.cpp.

◆ print_assignment()

void fawkes::HungarianMethod::print_assignment ( )

Print the assignment matrix.

Definition at line 113 of file hungarian.cpp.

References p, and print_matrix().

Referenced by print_status().

◆ print_cost_matrix()

void fawkes::HungarianMethod::print_cost_matrix ( )

Print the cost matrix.

Definition at line 123 of file hungarian.cpp.

References p, and print_matrix().

Referenced by print_status().

◆ print_matrix()

void fawkes::HungarianMethod::print_matrix ( int **  C,
int  rows,
int  cols 
)
protected

Print matrix to stdout.

Parameters
Cvalues
rowsnumber of rows
colsnumber of columns

Definition at line 72 of file hungarian.cpp.

Referenced by print_assignment(), and print_cost_matrix().

◆ print_status()

void fawkes::HungarianMethod::print_status ( )

Print the current status.

Prints cost matrix followed by assignment.

Definition at line 134 of file hungarian.cpp.

References print_assignment(), and print_cost_matrix().

◆ solve()

void fawkes::HungarianMethod::solve ( )

Solve the assignment problem.

This method computes the optimal assignment.

Definition at line 251 of file hungarian.cpp.

References free(), and p.

Referenced by TabletopObjectsThread::loop().

Member Data Documentation

◆ p

hungarian_problem_t* fawkes::HungarianMethod::p

our problem instance member.

Definition at line 75 of file hungarian.h.

Referenced by free(), get_assignment(), HungarianMethod(), init(), print_assignment(), print_cost_matrix(), solve(), and ~HungarianMethod().


The documentation for this class was generated from the following files: