-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrb.h
More file actions
106 lines (89 loc) · 2.4 KB
/
grb.h
File metadata and controls
106 lines (89 loc) · 2.4 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
//
// Created by nandgate on 6/5/24.
//
//#ifndef SGUFP_SOLVER_GRB_H
//#define SGUFP_SOLVER_GRB_H
#pragma once
#include "gurobi_c++.h"
#include "Network.h"
#include <vector>
#include "Cut.h"
#include <memory>
#include <cstring>
using namespace std;
class GuroSolver{
const shared_ptr<Network> networkPtr;
public:
GRBEnv environment;
int n;
shi *y_bar;
CutCoefficients Y_bar_coef;
// gurobi variables
GRBVar* alpha;
GRBVar** beta;
GRBVar** gamma;
GRBVar** sigma;
GRBVar** phi;
GRBVar*** lambda;
GRBVar*** mu;
GRBModel model;
GuroSolver(const shared_ptr<Network>& networkPtr_, const GRBEnv& env_): networkPtr{networkPtr_},
environment(env_), n{static_cast<int>(networkPtr_->n)}, model {environment} {
// set model parameters and initialize gurobi variables.
model.set(GRB_IntParam_OutputFlag, 0);
model.set(GRB_IntParam_Threads, 1);
model.set(GRB_IntParam_InfUnbdInfo, 1);
alpha = model.addVars(n, GRB_CONTINUOUS);
beta = new GRBVar*[n];
gamma = new GRBVar*[n];
sigma = new GRBVar*[n];
phi = new GRBVar*[n];
lambda = new GRBVar**[n];
mu = new GRBVar**[n];
y_bar = new shi[n*n*n];
initializeVariables();
addConstraints();
// initialize cut coefficients
const auto& nodes = networkPtr->networkNodes;
const auto& arcs = networkPtr->networkArcs;
const auto& processingOrder = networkPtr->processingOrder;
for (uint i0 = 0; i0 < processingOrder.size(); i0++){
uint arcID = processingOrder[i0].second;
uint i = arcs[arcID].tailId;
uint q = arcs[arcID].headId;
for (uint outArc : nodes[q].outgoingArcs){
uint j = arcs[outArc].headId;
Y_bar_coef[make_tuple(i, q, j)] = 0.0;
}
}
}
void initializeVariables();
Cut solveSubProblem(const vector<vector<vector<shi>>> &y_bar);
std::pair<CutType, Inavap::Cut> solveSubProblem(const vector<int16_t>& path);
Cut solveSubProblemInstance(const vector<vector<vector<shi>>> &y_bar, int scenario);
void addConstraints();
~GuroSolver(){
// clear up the heap and gurobi variables.
delete[] y_bar;
for (int i = 0; i < n; i++){
delete[](beta[i]);
delete[](gamma[i]);
delete[](sigma[i]);
delete[](phi[i]);
for (int j = 0; j < n; j++){
delete[](lambda[i][j]);
delete[](mu[i][j]);
}
delete[](lambda[i]);
delete[](mu[i]);
}
delete[](alpha);
delete[](beta);
delete[](gamma);
delete[](sigma);
delete[](phi);
delete[](lambda);
delete[](mu);
}
};
//#endif //SGUFP_SOLVER_GRB_H