-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProbMIP.h
More file actions
223 lines (191 loc) · 6.82 KB
/
Copy pathProbMIP.h
File metadata and controls
223 lines (191 loc) · 6.82 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <cplex.h>
#include <ctype.h>
#include <fstream>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
// Define global constants
#define NAMELEN 50
#define INFBOUND 1e+20
class ProbMIP {
public:
ProbMIP();
ProbMIP(CPXENVptr env);
virtual ~ProbMIP();
double MIPScalarproduct(const double* array1, const double* array2, int beg, int end);
/**
* This function computes the scalar product of two vectors given by the elements of
* two arrays with same beginning and ending index specified
* @param array1 first array
* @param array2 second array
* @param beg beginning index for both arrays
* @param end ending index for both arrays
* @return returns the scalar product of the two arrays
*/
double MIPL1Norm(const double* array1, const double* array2, int len);
/**
* This function computes the L1 norm ||array1 - array2|| given the lenght of the arrays
* @param array1 first array
* @param array2 second array
* @param len lenght of the arrays
* @return returns the L1 norm of the difference of two arrays
*/
int MIPSetupMIP(char* filename);
/**
* Sets up the MIP program: reads an MPS file
* @param filename name of the MPS file
* Set the problem up as a maximization problem
* Calls MIPMallocRegMIP() to allocate memory of RegMIP arrays
* @return 0 if memory allocation is success, otherwise return a nonzero integer
*/
int MIPWriteProblem(char* newname);
/**
* Writes the MIP prblem object as an MPS file
* @param filename name of the MPS file written
*/
int MIPWriteDualRelaxed();
/**
* Write the dual relaxed problem as filename_dual.mps
* The initial coefficient c must be set before calling this method
* @return 0 if write is success, otherwise return a nonzero integer
*/
int MIPMallocRegMIP();
/**
* Dynamically allocate memory for required member variables
* mipsigma_nrows and mipsigma_ncols must be set after the regularized MIP problem is set
*/
int MIPSolveMIP();
/**
* This method calls CPLEX to solve the MIP problem and sets
* the optimal objective value and current optimal solution
* @return 0 on success, otherwise returns a nonzero value
*/
int MIPSetupCutMIP(char* newfname);
/**
* This method sets up the MIP Cut problem
*/
int MIPSetupRegMIP();
/**
* This method sets up the Regularized MIP problem
* Converts the MIP problem read via MIPSetupMIP()
* MIP problem must be read using MIPSetupMIP(char* filename)
* Initial objective coefficient must be set before solving
* the regularized MIP by calling MIPSetupObjcoeffsigma()
* Required solution x_d should be obtained
* Adds the necessary additional columns and rows to get the regularized problem
*/
int MIPSetSigma(const double* solnx);
/**
* Set/Update the value of sigma for the regularized problem
* Must be called before MIP Reg is solved
* @param solnx The incumbent solution x^k to cut mip
*/
int MIPSetupReqdSolnandIniObj(int seed);
/**
* This method gets the required solution x^d and initial cost vector c
* @param seed srand() value to be used
* Needs to be called before dual is written using MIPWriteDualRelaxed()
*/
int MIPGetIniObj(const int* arraylb, const int* arrayub, int seed);
/**
* This method gets the initial cost vector c, having set the value of x^d
* @param arraylb the lower boud on coefficient values
* @param arraylb the upper boud on coefficient values
* @param seed srand() value to be used
* Needs to be called before dual is written using MIPWriteDualRelaxed()
*/
int MIPSetCurrobjsigma(const double* objd);
/**
* This method setsup the current objective coefficients for the regularized MIP
* when an objective array is passed as an argument
* @param objd The current objective coefficient obtained from the Cost Generator LP
* mipsigma_ncols must be set before calling this method
* Value of sigma must be set/updated if necessary using MIPSetSigma()
* obj coeff = (d^k - sigma) e - (d^k + sigma) f
* Values are obtained from the cost generator LP
*/
int MIPSetCurrobjsigma();
/**
* This method setsup the current objective coefficients for the regularized MIP
* when no objective array is passed as an argument
* The incumbent objective is used as to get the objective
* mipsigma_ncols must be set before calling this method
* Value of sigma must be set/updated if necessary using MIPSetSigma()
* obj coeff = (d^k - sigma) e - (d^k + sigma) f
* Values are obtained from the cost generator LP
*/
int MIPSetCurrobj(const double* objd);
/**
* Gets the objective coefficient d^k for the upcoming iteration
* The GenLP should provide the current objective coefficient except for the initial iteration
* For Regularized MIP MIPSetupObjcoeffsigma() must be called
* after this method to set the objective coefficients for regularized MIP
*/
double MIPRegsetIncumsolnxandObjval();
/**
* Sets the incumbant solution after solving Regularized MIP
* x^k = x^d + e^k - f^k; objval = objval_regMIP + d^k x^d
* Return diff = d^k x^k - sigma ||x^k -x ^d|| - d^k x^d = objval_regMIP
*/
int MIPCutsetIncumsolnxandObjval();
/**
* Sets the incumbant solution after solving Cut MIP
*/
int MIPGetSoln();
/**
* Sets and prints the temp solution
*/
int MIPSetCutSoln();
/**
* This method sets the current solution x^k to the incumbant solution array
*/
int MIPSetRegSoln();
/**
* This method sets the curent solutions y^k, e^k, and f^k
* Then the incumbent array is set ti x^k_sigma = x^d + e^k - f^k
*/
double* MIPGetIncumsolnx();
/**
* Returns the incumbent solution set after solving Regularized MIP
*/
static double* MIPGetreqdsoln();
/**
* Returns the required solution x^d
*/
static double* MIPGetiniobjcoeff();
/**
* Returns the initial objective coefficient c
*/
double MIPChecktermcondn();
/**
* Compare the obj value of MIPCut/MipReg with c^k x^d
* Return the difference
*/
static int MIPGetncols();
/**
* Returns mip_ncols
*/
private:
static char* filename;
static char* dualname;
static double* reqd_soln;
static double* ini_objcoeff;
static double* orig_objcoeff; //Cost vector in the file read
static int mip_ncols; // Current MIP number of columns (variables)
static int mip_nrows; // Current MIP number of rows (constraints)
CPXENVptr env; // CPLEX environment
CPXLPptr mip; // Pointer to CPLEX MIP obj
int status;
int solnstat;
double sigma;
double objval, objshift;
double* curr_objcoeff;
double* incum_solnx; //Solution x^k to be passed to cost generator LP
double* opt_soln;
int mipsigma_nrows;
int mipsigma_ncols;
int mipsigma_ncolswithx;
double* curr_objcoeffsigma;
double* incum_solnxsigma;
};