-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLPSolver.h
More file actions
75 lines (61 loc) · 2.7 KB
/
LPSolver.h
File metadata and controls
75 lines (61 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* LPSolver.h:
* This module is used to solve a sudoku board with LP or with ILP.
*
* It supplies an interface that allows the user to receive the assignment received for
* each variable through the LP, as well as information to which (i,j,v)'s weren't assigned
* a variable (where i is a row index, j is a column index, and v is a value),
* and why (cell contained a value before, or v is illegal for the cell).
*/
#ifndef LPSOLVER_H_
#define LPSOLVER_H_
#include "StandardLinkedList.h"
/*
* LPSolution is used to hold the information received from the LP solver.
* It stores and later allow to receive the assignment for each variable.
*
* Also, for each cell (i,j) with value v which wasn't assigned a variable, it
* holds the information whether (i,j) wasn't empty, or it was empty but
* value v was illegal for the cell.
*
* If a change in the board is made after creating it (via the LP solver), the stored information may be no longer relevant.
*
* Fields:
* - Mapping is an array of StandardLists. The index (i,j) represents the cell (i,j).
* If v exists in the StandardList of (i,j), it means there is a variable (i,j,v), and it's index is indexVar (of the relevant node).
* - Sol stores the solution from the LP.
* - foundSolution is set to 1 if LP found a solution to the board, 0 if there is no solution, and -1 if the LP solver encoutered an error.
*/
typedef struct {
int N;
StandardList **mapping;
double *sol;
int foundSolution;
} LPSolution;
/*
* Solves the board using linear programming. Returns a LPSolution struct with the solution information.
* @param integerSolution - determines whether the solver will use LP (0) or ILP (1).
*/
LPSolution* getLPSolution(SudokuBoard *sudoku, int integerSolution);
/*
* Returns the assignment of cell (i,j) with value v (i.e. variable (i,j,v)), received via LP.
* If (i,j,v) doesn't have a variable:
* - If it's because cell (i,j) already contains a value, returns -1.
* - If it's because value v is illegal for cell (i,j), in respect to current board state, returns -2.
*/
double getVariableAssignment(LPSolution *boardSol, int i, int j, int v);
/*
* Returns 1 if the board is solveable, 0 if unsolveable, and -1 if LP solver encountered an error.
*/
int getSolutionStatus(LPSolution *boardSol);
/*
* Destroys boardSol and free it's memory resources.
*/
void destroyLPSolution(LPSolution *boardSol);
/* ======== TEST FUNCTIONS (remove before submitting) ============ */
LPSolution* initializeLPSolution(int N);
int getN(LPSolution *boardSol);
StandardList **getLists(LPSolution *boardSol);
void addVariable(LPSolution *boardSol, int i, int j, int v, int index);
int getVariableIndex(LPSolution *boardSol, int i, int j, int v);
#endif /* GUROBI_H */