Commit 24028027 authored by Valentin Antuori's avatar Valentin Antuori
Browse files

better LB + fix temperature on extend_rollout

parent 426b3e93
......@@ -171,6 +171,7 @@ bool DFSRollout::trainOk(const int i) const {
void DFSRollout::get_operations() {
actions.clear();
other_operations.clear();
int p;
for(int i{0}; i<data.nb_components; ++i) {
if(period[i] == data.get_nb_periods(i))
......@@ -179,9 +180,15 @@ void DFSRollout::get_operations() {
p = data.get_pickfull_idx(i, period[i]);
if(trainOk(p))
actions.push_back(p);
else
other_operations.push_back(p);
p = data.get_pickempty_idx(i, period[i]);
if(trainOk(p))
actions.push_back(p);
else
other_operations.push_back(p);
} else if(data.is_pickup(prev_operation[i])) {
if(num_operation[i] != 1 && num_operation[i] != 3){
// std::cout << num_operation[i] <<"/" << period[i] << std::endl;
......@@ -205,10 +212,16 @@ void DFSRollout::get_operations() {
p = data.get_pickempty_idx(i, period[i]);
if(trainOk(p))
actions.push_back(p);
else
other_operations.push_back(p);
} else {
p = data.get_pickfull_idx(i, period[i]);
if(trainOk(p))
actions.push_back(p);
else
other_operations.push_back(p);
}
}
}
......@@ -324,6 +337,13 @@ void DFSRollout::compute_distances() {
min_action_tardiness = std::min(min_action_tardiness, tardiness[op]);
}
// Compute tardiness for other operations for LB computation
for(auto op: other_operations) {
compute_distance(op);
max_action_tardiness = std::max(max_action_tardiness, tardiness[op]);
min_action_tardiness = std::min(min_action_tardiness, tardiness[op]);
}
maximum_tardiness.push_back(std::max(maximum_tardiness.back(), max_action_tardiness));
maximum_positive_tardiness.push_back(max(0, maximum_tardiness.back()));
}
......@@ -468,6 +488,7 @@ void DFSRollout::extend_rollout(int ub) {
bool can_stop = false;
restore_state();
temperature = base_temperature;
if(debug_dfs)
std::cerr << "Restored" << std::endl;
......@@ -782,17 +803,17 @@ int DFSRollout::search(int ub, int lb_depth) {
if(verbose)
{
cout << "d depth=" << sequence.size() << "(lmax="<< get_tardiness() << ") iter=" << iter << endl;
if(sequence.size() == 284){
for(auto elt : maximum_positive_tardiness)
std::cout << elt << " ";
std::cout << std::endl << "=====" << std::endl;
for(auto elt : maximum_tardiness)
std::cout << elt << " ";
std::cout << std::endl << "=====" << std::endl;
for(auto elt : sequence)
std::cout << elt << " ";
std::cout << std::endl;
}
// if(sequence.size() == 182){
// for(auto elt : maximum_positive_tardiness)
// std::cout << elt << " ";
// std::cout << std::endl << "=====" << std::endl;
// for(auto elt : maximum_tardiness)
// std::cout << elt << " ";
// std::cout << std::endl << "=====" << std::endl;
// for(auto elt : sequence)
// std::cout << elt << " ";
// std::cout << std::endl;
// }
}
save_state();
}
......
......@@ -144,6 +144,9 @@ public:
}
vector<int> maximum_tardiness;
vector<int> maximum_positive_tardiness;
private:
......@@ -157,9 +160,7 @@ private:
int start_train_length{0};
//
vector<int> maximum_tardiness;
vector<int> maximum_positive_tardiness;
// the current period, for every component
......@@ -185,6 +186,8 @@ private:
// the set of possible operations
vector<int> actions;
// The set of operations that are not in actions due to the capacity constraint, used for earlier tardiness computation
vector<int> other_operations;
// used to store the distance of the actions
vector<int> distance;
......
......@@ -273,11 +273,11 @@ int main(int argc, char **argv){
}else
{
double sol_rol = 0;
/*
DFSRollout rollout(data[0]);
rollout.temperature = opt.temperature;
set_default_temperature(opt.temperature);
double sol_rol = 0;
double sol_greed = 0;
double sol_greed2 = 0;
......@@ -303,10 +303,21 @@ int main(int argc, char **argv){
std::cout << sol_rol << " / " << sol_greed << " / " << sol_greed2 << std::endl;
//*/
std::vector<int> v{278,100,438,279,494,495,316,550,439,436,101,338,317,398,399,396,339,437,60,258,259,42,61,376,397,358,377,43,40,378,379,102,103,104,551,548,549,256,41,576,257,416,577,578,579,610,417,418,611,336,419,626,359,356,105,106,337,62,63,22,107,594,23,20,21,296,627,624,357,318,319,110,625,616,111,442,443,554,555,108,595,592,593,440,441,552,553,608,297,298,299,602,109,114,609,260,261,262,263,46,115,112,617,584,47,618,113,380,381,402,403,64,619,26,585,422,423,420,421,586,27,24,587,382,383,400,401,44,603,600,65,118,601,300,25,66,301,302,45,444,67,322,303,340,119,116,445,446,323,360,117,122,341,342,361,362,363,320,123,120,321,558,559,556,557,622,447,614,121,630,631,628,623,620,629,124,343,304,125,126,305,306,307,266,267,324,127,426,427,598,599,30,31,28,325,326,29,264,265,404,405,48,621,386,387,384,49,364,327,448,449,450,451,128,615,424,425,590,385,406,407,68,129,130,69,70,71,562,563,560,131,50,561,612,613,580,581,132,133,134,51,596,365,366,591,588,367,346,347,344,345,606,135,32,607,410,411,308,33,34,589,454,455,452,453,430,431,428,429,270,271,268,269,408,409,390,391,388,389,52,53,54,55,35};
std::vector<int> v{168,464,0,169,170,1,520,171,318,465,102,319,316,103,100,521,522,523,238,239,236,237,2,396,101,376,3,317,20,397,398,377,378,358,399,21,22,258,23,172,173,174,175,40,379,106,359,259,492,41,42,493,494,495,550,436,107,104,437,551,548,438,549,439,276,277,278,279,356,256,105,466,467,357,43,634,176,257,177,178,82,83,80,81,296,179,468,297,298,469,62,63,60,299,616,635,440,554,555,108,441,336,109,110,337,338,61,626,339,111,418,526,419,416,417,442,527,524,627,624,443,625,182,525,112,422,423,420,421,586,183,180,617,618,587,584,113,114,181,619,86,262,115,552,87,84,585,608,609,610,553,263,496,497,498,499,320,611,240,241,186,85,300,187,184,321,322,185,242,243,578,579,280,323,46,301,470,471,4,47,44,5};
DFSRollout rollout(data[0]);
int best = numeric_limits<int>::min();
for(int i = 0; i < 2000; ++i){
rollout.clear();
for(auto elt : v)
rollout.do_op(elt);
rollout.replay(v);
rollout.extend_rollout(numeric_limits<int>::max());
sol_rol = sol_rol + (rollout.get_tardiness() - sol_rol)/(i+1);
best = max(rollout.get_tardiness(), best);
}
std::cout << sol_rol << std::endl;
std::cout << best << std::endl;
// rollout.replay(v);
}
......
......@@ -200,10 +200,14 @@ Solution solve(const Instance& data, double c, int timeout)
int iteration = 0;
while(upper_bound > 0 && std::chrono::steady_clock::now() < run_until)
{
if(iteration > 0)
exit(1);
// for(auto elt : rollout.maximum_tardiness)
// std::cout << elt << " " ;
// std::cout << std::endl;
// if(iteration > 0)
// exit(1);
// debug_dfs = true;
rollout.verbose = true;
// rollout.verbose = true;
// if(iteration == 190417){
// debug_dfs = true;
// rollout.verbose = true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment