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

make

parent bb16bd74
......@@ -709,14 +709,15 @@ void DFSRollout::restart(const int lvl, int& restart_size, int& restart_limit)
void DFSRollout::warm_up(int step, int restart_prevision)
{
double a = (warm - cold)/std::max(1, (restart_prevision*restart_prevision - 1));//max in order to prevent 0 denominator
double b = cold;
temperature = a*step*step + b; // basic quadratic function from two points (base and target temperature)
// double a = (warm - cold)/std::max(1, (restart_prevision*restart_prevision - 1));//max in order to prevent 0 denominator
// double b = cold;
// temperature = a*step*step + b; // basic quadratic function from two points (base and target temperature)
temperature = temperature * warming_factor;
if(verbose)
std::cout << "d temperature=" << temperature <<", a=" << a << ", b=" << b << ", step=" << step << std::endl;
std::cout << "d temperature=" << temperature << std::endl;
if(debug_dfs){
std::cerr << "Restart prevision=" << restart_prevision << std::endl;
std::cerr << "d temperature=" << temperature <<", a=" << a << ", b=" << b << ", step=" << step << std::endl;
// std::cerr << "Restart prevision=" << restart_prevision << std::endl;
std::cerr << "d temperature=" << temperature << std::endl;
}
}
......@@ -758,9 +759,6 @@ int DFSRollout::search(int ub, int lb_depth) {
cout.precision(6);
double sum_domain_size = 0;
int nb_dom = 0;
start_level = sequence.size();
start_train_length = train_length;
......@@ -769,6 +767,9 @@ int DFSRollout::search(int ub, int lb_depth) {
start_prev_operation = prev_operation;
start_num_operation = num_operation;
double avg_action = 0;
int nb = 0;
int iter{0};
int restart_limit{restart_base};
......@@ -832,9 +833,9 @@ int DFSRollout::search(int ub, int lb_depth) {
domain[i].push_back(*a);
}
// std::cout << actions.size() << " / " << domain[i].size() << std::endl;
sum_domain_size += domain[i].size();
nb_dom++;
avg_action += (domain[i].size() - avg_action) / ++nb;
// if randomized, swap the first action with one chosen at random given the distribution of the heuristic
if(randomized) {
......@@ -850,6 +851,11 @@ int DFSRollout::search(int ub, int lb_depth) {
}
std::swap(*act, *domain[i].begin());
}
// if(domain[i].size() > 1){
// for(auto elt : domain[i])
// std::cout << elt << " " ;
// std::cout << std::endl;
// }
// branch left
action[i] = domain[i].begin();
......@@ -869,28 +875,36 @@ int DFSRollout::search(int ub, int lb_depth) {
// print_step();
}
if(first_fail and auto_limit)
if(auto_limit && first_fail)
{
first_fail = false;
max_iter = 1;
if(first_fail){
max_iter = 1;
}
int tmp = 1;
if(sequence.size() == data.nb_tasks || first_tard_depth > lb_depth) // improvement of lmax lupper bound, or longer sequence without tardiness
{
max_iter = FAIL_LIMIT;
tmp = FAIL_LIMIT;
}else if(first_tard_depth > ALPHA * lb_depth)
{
double term = (1 - (lb_depth - first_tard_depth)/(lb_depth - ALPHA*lb_depth));
term = (double)first_tard_depth/lb_depth;
max_iter = FAIL_LIMIT * term * term;
// term = (double)first_tard_depth/lb_depth;
tmp = FAIL_LIMIT * term * term;
}
// verbose = max_iter > 1;
bool new_iter = false;
if(tmp > max_iter ){
new_iter = true;
max_iter = tmp;
}
if(verbose){
std::cout << "o max_iter=" << max_iter << std::endl;
}
// warming computation
if(restart_base && warming && max_iter > 1)
if(new_iter && restart_base && warming)
{
restart_prevision = 0;
int tmp_limit = restart_base;
int tmp_iter = tmp_limit;
......@@ -902,6 +916,7 @@ int DFSRollout::search(int ub, int lb_depth) {
tmp_iter += tmp_limit;
}
}
first_fail = false;
}
// the branch is full
......@@ -923,6 +938,9 @@ int DFSRollout::search(int ub, int lb_depth) {
}
if(restart_base and iter >= restart_limit) {
std::cout << "Avg Actions : " << avg_action << std::endl;
avg_action = 0;
nb = 0;
restart(start_level, restart_size, restart_limit);
if(warming){
warm_up(nb_restart, restart_prevision);
......@@ -932,6 +950,8 @@ int DFSRollout::search(int ub, int lb_depth) {
}
// std::cout << sequence.size();
// backtrack
while(sequence.size() > start_level) {
// undo until the lower bound is lower than the upper bound
......@@ -941,7 +961,7 @@ int DFSRollout::search(int ub, int lb_depth) {
i = sequence.size();
++action[i];
} while(sequence.size() > start_level and get_tardiness() >= ub);
if(sequence.empty() || get_tardiness() >= ub) {
if(get_tardiness() >= ub) {
break;
}
......@@ -968,7 +988,12 @@ int DFSRollout::search(int ub, int lb_depth) {
commit(*action[i]);
break;
}
}
// if(sequence.empty() || sequence.size() == start_level)
// {
// break;
// }
}
// std::cout << " => " <<sequence.size() << " " << start_level <<std::endl;
// if no tardiness after backtrack, then update tardi_depth
if(get_tardiness() == 0)
......@@ -977,9 +1002,21 @@ int DFSRollout::search(int ub, int lb_depth) {
}
// check if the algorithm should stop
if(sequence.empty() and action[0] == domain[0].end()) {
if(sequence.empty() and action[0] == domain[0].end()
|| sequence.size() == start_level and action[start_level] == domain[start_level].end()
) {
// if(verbose)
cout << "o search tree exhausted: " << best_tardiness << " at temperature " << temperature << " \n" ;
if(warming){
std::cout << "Avg Actions : " << avg_action << std::endl;
avg_action = 0;
nb = 0;
restart(start_level, restart_size, restart_limit);
warm_up(nb_restart, restart_prevision);
continue;
}
} else if(best_tardiness == 0) {
if(verbose)
cout << "o solution found\n";
......@@ -991,10 +1028,7 @@ int DFSRollout::search(int ub, int lb_depth) {
break;
}
// std::cout << "End - Saved = " << best_tardiness << ", " << _tardi_depth << ", size = " << best_sequence.size() <<std::endl;
// std::cout << sum_domain_size/nb_dom << std::endl;
// std::cout << tardiness_at_fail << " - " << sequence.size() << std::endl;
// std::cout << "Saved = " << best_tardiness << ", " << _tardi_depth <<", " << best_sequence.size() << std::endl;
return max_iter;
}
......
......@@ -3,7 +3,7 @@
#define __DFSROLLOUT_H
#define DEBUG_DFS_ROLLOUT
// #define DEBUG_DFS_ROLLOUT
......@@ -74,7 +74,8 @@ public:
double restart_factor{1.2};
bool warming{WARMING};
double cold{0.00001};
double warming_factor{1.4};
double cold{0.0001};
double warm{0.1};
// Used in DFS, automatically set if auto_limit
......
......@@ -383,38 +383,13 @@ Solution solve(const Instance& data, double c, int timeout)
// backup_value = marginal_incr + decay*backup_value;
// }
// }
}else if(aggregation == 2){ //depth only
backup_value = rollout_depth;
}else if(aggregation == 3)
{
// inverse s shaped ?
// 1/(1+((x/N)/(1-(x/N)))^beta)
}
// if(iteration == 1)
// exit(1);
// tricks for displaying the mean tardiness for each node
// bool start = false;
// for(auto elt : rollout.sequence){
// if(start){
// sol.append(elt);
// }
// if(elt == node_vector[current_node_idx].action){
// start = true;
// }
// }
// // for(int i = 0; i < rollout.sequence.size(); ++i)
// // {
// // std::cout << rollout.sequence[i] << "/" << sol.sequence[i] << std::endl;
// // }
// rollout.clear();
// for(int i = 0; i < sol.size(); ++i)
// {
// rollout.do_op(sol.sequence[i]);
// if(sol.sequence[i] == node_vector[current_node_idx].action){
// break;
// }
// }
// rollout.greedy_stochastic(_upper);
// std::cerr << "greed=" << rollout.get_tardiness() <<", depth=" << rollout.tardi_depth << std::endl;
// balance = balance + ((rollout_tardiness - rollout.get_tardiness()) - balance)/(++n_balance);
////////////////////////////
///////// BACKUP /////////
......
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