-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.cpp
executable file
·72 lines (63 loc) · 1.48 KB
/
node.cpp
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
/*
* node.cpp
*
* Created on: Nov 25, 2015
* Author: Matt
*/
#include "node.h"
#include "source.h"
node::node(vector <Item> itemsTaken, int costsofar) {
pset = itemsTaken;
csf = costsofar;
lowerBound = csf;
UpperBound = calcUpperBound();
}
node::node(const node &nde){
UpperBound = nde.UpperBound;
lowerBound = nde.lowerBound;
csf = nde.csf;
for (unsigned int i = 0; i < nde.pset.size(); i++){
Item temp(0, 0 , 0);
temp = nde.pset[i];
pset.push_back(temp);
}
}
int node::calcLowerBound(){
int lb;
if (getType() == 0) lb = csf; //weaker lower bound
else {lb = csf + guaranteedFutureCost(getWeightOfSet(), pset.size()-1);/*stronger lower bound*/}
return lb;
}
int node::calcUpperBound(){
int ub = csf;
int gfc;
//if (getType() == 0){
BadFeasibleFutureCost(getWeightOfSet(), pset.size()-1);
//}
//else {gfc = FeasibleFutureCost(getWeightOfSet(), pset.size()-1);}
ub += gfc;
return ub;
}
void node::addItem(Item add){
if (add.mass + getWeightOfSet() <= maxWeight()){
pset.push_back(add);
if (add.id == 0) csf += list()[pset.size()-1].value;
lowerBound = calcLowerBound();
UpperBound = calcUpperBound();
}
else {
pset.push_back(add);
lowerBound = 9999999;
}
}
int node::getWeightOfSet(){
int weight(0);
for (unsigned int i = 0; i < pset.size(); i++){
if (pset[i].id != 0)
weight += pset[i].mass;
}
return weight;
}
node::~node() {
// TODO Auto-generated destructor stub
}