Skip to content

Commit 8692ebe

Browse files
committed
not branch on vehicle number
1 parent 6b747fa commit 8692ebe

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

main.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int main2(){
5757
vrp.init(costumerCnt, seed, maxWeight);
5858
}
5959
} else if(input=="check" || input=="c") {
60-
vrp.checkMIP(false);
60+
vrp.checkMIP(true);
6161
} else if(input=="checkprintsolutionarcs"){
6262
vrp.checkMIP(false, true);
6363
} else if (input=="checkwithconditions" || input=="cc"){
@@ -180,9 +180,11 @@ int main(){
180180
bool earlyStop;
181181
VRP vrp("hun-sc-ncn.lgf");
182182
while(cin >> costumerCnt >> seed >> maxWeight >> smoothingParameter >> earlyStop){
183-
cout << costumerCnt << " " << seed << " " << maxWeight << " " << flush;
183+
cout << costumerCnt << "\t" << seed << "\t" << maxWeight << "\t" << flush;
184184
vrp.init(costumerCnt, seed, maxWeight);
185185
vrp.callBranchAndPrice(smoothingParameter, earlyStop);
186+
cout << endl;
187+
//cout.precision(12);
186188
//vrp.checkMIP();
187189
}
188190
return 0;

vrp.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void VRP::checkMIP(bool printEps, bool printSolutionArcs,
363363
cout << "Elapsed real time: " << timer.realTime() << "s" << endl;
364364
cout << "Elapsed user time: " << timer.userTime() << "s" << endl;
365365
} else {
366-
cout << " " << timer.realTime() << " " << timer.userTime() << " " << mip.solValue() << endl;
366+
cout << timer.realTime() << "\t" << timer.userTime() << "\t" << mip.solValue() << endl;
367367
}
368368

369369
if(printSolutionArcs){
@@ -1032,15 +1032,14 @@ void BranchAndPrice::printMasterLPSolution()
10321032
}
10331033

10341034
///Calls createMasterLP and recursiveBranch
1035-
void BranchAndPrice::branchAndBound()
1036-
{
1035+
void BranchAndPrice::branchAndBound() {
10371036
classTimer.restart();
10381037
bestCost = BIG_VALUE;
10391038
if (PRINT) cout << "Branch and bound started: " << endl;
10401039
int branchedNodes = 0;
10411040
createMasterLP();
10421041
recursiveBranch(branchedNodes);
1043-
bool endedInTime=(classTimer.realTime()<=TIME_LIMIT);
1042+
bool endedInTime = (classTimer.realTime() <= TIME_LIMIT);
10441043
classTimer.stop();
10451044

10461045
if (PRINT) {
@@ -1054,7 +1053,8 @@ void BranchAndPrice::branchAndBound()
10541053
cout << "Number of added cols: " << cols.size() << endl;
10551054
cout << "Visited branching nodes: " << branchedNodes << endl;
10561055
} else {
1057-
cout << endedInTime << " " << classTimer.realTime() << " " << classTimer.userTime() << " " << bestCost << endl;
1056+
cout << endedInTime << "\t" << classTimer.realTime() << "\t" << classTimer.userTime();
1057+
cout << "\t" << bestCost << "\t" << flush;
10581058
}
10591059
myAssert(countArcs(g) == n * (n - 1), "Wrong arc count at the end of branchAndBound!");
10601060
}
@@ -1072,13 +1072,14 @@ void BranchAndPrice::recursiveBranch(int& branchedNodes)
10721072
if(PRINT) cout << "New branching node: " << branchedNodes << endl;
10731073
if(!solveMasterLPwithSmoothing()){
10741074
return;
1075-
} else if(masterLP.primal()>bestCost-5000) {
1075+
} else if(masterLP.primal()>bestCost-OPTIMUM_DIFF) {
10761076
if(PRINT) cout << "BOUND" << endl;
10771077
return;
10781078
}
10791079

10801080
double vehicleNumber=masterLP.primal(vehicleNumberCol);
1081-
Lp::Row tempRow=INVALID;
1081+
//Lp::Row tempRow=INVALID;
1082+
/*
10821083
if(!isWhole(vehicleNumber)){
10831084
//branch on vehicle number
10841085
tempRow=masterLP.addRow(vehicleNumberCol<=floor(vehicleNumber));
@@ -1093,6 +1094,7 @@ void BranchAndPrice::recursiveBranch(int& branchedNodes)
10931094
if(PRINT) cout << "Remove: vehicleNumberCol >= " << ceil(vehicleNumber) << endl;
10941095
masterLP.erase(tempRow);
10951096
} else {
1097+
*/
10961098
//branch on arcs
10971099
ListDigraph::Arc arcToBranch = INVALID;
10981100
findArcToBranch(arcToBranch);
@@ -1181,7 +1183,7 @@ void BranchAndPrice::recursiveBranch(int& branchedNodes)
11811183
myAssert(countArcs(g) == originalArcCount, "Arc(s) vanished!");
11821184
if (PRINT) cout << "Remove: arc =0" << endl;
11831185
}
1184-
}
1186+
//}
11851187
}
11861188

11871189
///If a column contains arc, than changes its objective coefficient to big value

vrp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <algorithm>
66
#include <iostream>
7+
#include <fstream>
78
#include <lemon/arg_parser.h>
89
#include <lemon/color.h>
910
#include <lemon/dijkstra.h>
@@ -21,7 +22,10 @@
2122

2223
#define PRINT false
2324
#define COLUMN_PRINT false
25+
//max running time for the branch & prize algorithm:
2426
#define TIME_LIMIT 910
27+
//max difference from optimum: used for better bound in the branch & bound algorithm:
28+
#define OPTIMUM_DIFF 1000
2529

2630
#ifndef VRP_H
2731
#define VRP_H
@@ -57,7 +61,7 @@ class NodeLabels;
5761

5862
/// Solves the VRP with the branch and price algorithm
5963
class BranchAndPrice{
60-
private:
64+
public:
6165
bool createdMasterLP=false;
6266

6367
//Init data

0 commit comments

Comments
 (0)