Commit 2be48955 authored by Valentin Antuori's avatar Valentin Antuori
Browse files

remove experimental library

parent 45857af5
......@@ -4,7 +4,7 @@ project(main)
#find_package(Torch REQUIRED)
link_libraries(stdc++fs)
#link_libraries(stdc++fs)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
......
......@@ -698,6 +698,11 @@ void DFSRollout::restart(const int lvl, int& restart_size, int& restart_limit)
first_tard_depth = sequence.size();
}
if(warming){
temperature += warming_step;
// std::cout << "T = " << temperature << std::endl;
}
}
void DFSRollout::clear() {
......@@ -746,6 +751,8 @@ void DFSRollout::clear() {
///*
int DFSRollout::search(int ub, int ub_depth) {
cout.precision(6);
double sum_domain_size = 0;
int nb_dom = 0;
......@@ -764,6 +771,10 @@ int DFSRollout::search(int ub, int ub_depth) {
bool first_fail = true;
if(warming){
temperature = cold;
}
while(true) {
......@@ -775,26 +786,19 @@ int DFSRollout::search(int ub, int ub_depth) {
get_operations();
compute_distances();
// if(debug_dfs)
// {
// std::cerr << "Sequence : " << std::endl;
// for(auto elt: sequence)
// std::cerr << elt << " ";
// std::cerr << std::endl;
// std::cerr << "Action :" << std::endl;
// for(auto a{actions.rbegin()}; a!=actions.rend(); ++a) {
// std::cerr << *a << " ";
// }
// std::cerr << std::endl;
// }
if(sequence.size() > first_tard_depth && get_tardiness() == 0){
if(sequence.size() > first_tard_depth && get_tardiness() == 0){
first_tard_depth = sequence.size();
}
// fail because of the upper bound
if(get_tardiness() >= ub) {
if(sequence.size() > saved_sequence.size())
{
if(verbose)
{
cout << "d depth=" << sequence.size() << " iter=" << iter << endl;
}
save_state();
}
......@@ -857,8 +861,27 @@ int DFSRollout::search(int ub, int ub_depth) {
}else if(first_tard_depth > ALPHA * ub_depth)
{
double term = (1 - (ub_depth - first_tard_depth)/(ub_depth - ALPHA*ub_depth));
max_iter = FAIL_LIMIT * term * term;
// std::cout << max_iter << " : "<< tardiness_at_fail <<"/"<<ub << std::endl;
max_iter = FAIL_LIMIT * term * term;
}
// warming computation
if(warming && max_iter > 1)
{
int k = 0;
int tmp_limit = restart_base;
int tmp_iter = tmp_limit;
//how many restart ?
while(tmp_iter < max_iter)
{
k++;
tmp_limit *= restart_factor;
tmp_iter += tmp_limit;
}
warming_step = (warm-cold) / k;
// std::cout << "Iter : " << max_iter << std::endl;
// std::cout << "Warming step = " << warming_step << std::endl;
// std::cout << "Nb restart = " << k << std::endl;
}
}
......@@ -867,7 +890,7 @@ int DFSRollout::search(int ub, int ub_depth) {
save_state();
ub = get_tardiness();
if(verbose)
cout << "d lmax=" << best_tardiness << " iter=" << iter << endl;
cout << "d lmax=" << get_tardiness() << " iter=" << iter << endl;
if(verified)
verify("solution");
......
......@@ -69,6 +69,10 @@ public:
int restart_base{0};
double restart_factor{1.2};
bool warming{false};
double warming_step;
double cold{0.00001};
double warm{0.1};
// Used in DFS, automatically set if auto_limit
int max_iter{numeric_limits<int>::max()};
......
......@@ -4,7 +4,7 @@
#include <string>
#include <sys/stat.h>
#include <experimental/filesystem>
// #include <experimental/filesystem>
#include <typeinfo>
#include <list>
......@@ -27,7 +27,7 @@
#include <unistd.h>
namespace fs = std::experimental::filesystem;
// namespace fs = std::experimental::filesystem;
using namespace std;
/*
void random_tree()
......@@ -159,32 +159,32 @@ int main(int argc, char **argv){
set_default_temperature(opt.temperature);
/* instances(s) reading */
struct stat s;
if( stat(opt.instance_file.c_str(),&s) == 0 )
{
if( s.st_mode & S_IFDIR )
{
for(const auto& entry : fs::directory_iterator(opt.instance_file)){
string name = entry.path().string().substr(entry.path().string().find_last_of("/")+1);
data.emplace_back(entry.path().string());
std::cout << "Instance:\t" << name << std::endl << "nb tasks:\t" << data.back().nb_tasks << std::endl;
}
}
else if( s.st_mode & S_IFREG )
{
// struct stat s;
// if( stat(opt.instance_file.c_str(),&s) == 0 )
// {
// if( s.st_mode & S_IFDIR )
// {
// for(const auto& entry : fs::directory_iterator(opt.instance_file)){
// string name = entry.path().string().substr(entry.path().string().find_last_of("/")+1);
// data.emplace_back(entry.path().string());
// std::cout << "Instance:\t" << name << std::endl << "nb tasks:\t" << data.back().nb_tasks << std::endl;
// }
// }
// else if( s.st_mode & S_IFREG )
// {
string name = opt.instance_file.substr(opt.instance_file.find_last_of("/")+1);
data.emplace_back(opt.instance_file);
std::cout << "Instance:\t" << name << std::endl << "nb tasks:\t" << data.back().nb_tasks << std::endl;
}
else
{
//something else
}
}
else
{
cerr << "No file or directory found : " << opt.instance_file << endl;
}
// }
// else
// {
// //something else
// }
// }
// else
// {
// cerr << "No file or directory found : " << opt.instance_file << endl;
// }
srand (opt.seed);
......@@ -259,31 +259,37 @@ int main(int argc, char **argv){
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;
// double sol_rol = 0;
// double sol_greed = 0;
// double sol_greed2 = 0;
for(int i = 0; i < 2000; ++i)
{
WITHOUT_TARDINESS = false;
rollout.clear();
rollout.greedy_stochastic();
sol_rol = sol_rol + (rollout.get_tardiness() - sol_rol)/(i+1);
// for(int i = 0; i < 2000; ++i)
// {
// WITHOUT_TARDINESS = false;
// rollout.clear();
// rollout.greedy_stochastic();
// sol_rol = sol_rol + (rollout.get_tardiness() - sol_rol)/(i+1);
Solution sol(&data[0]);
build(sol);
sol_greed = sol_greed + (sol.lmax() - sol_greed)/(i+1);
// Solution sol(&data[0]);
// build(sol);
// sol_greed = sol_greed + (sol.lmax() - sol_greed)/(i+1);
WITHOUT_TARDINESS = true;
Solution sol2(&data[0]);
build(sol2);
sol_greed2 = sol_greed2 + (sol2.lmax() - sol_greed2)/(i+1);
// WITHOUT_TARDINESS = true;
// Solution sol2(&data[0]);
// build(sol2);
// sol_greed2 = sol_greed2 + (sol2.lmax() - sol_greed2)/(i+1);
// std::cout << rollout.get_tardiness() << " / " << sol.lmax() << std::endl;
}
// // std::cout << rollout.get_tardiness() << " / " << sol.lmax() << std::endl;
// }
// std::cout << sol_rol << " / " << sol_greed << " / " << sol_greed2 << std::endl;
std::cout << sol_rol << " / " << sol_greed << " / " << sol_greed2 << std::endl;
rollout.auto_limit = false;
rollout.verbose = true;
rollout.restart_base = 100;
rollout.max_iter = std::numeric_limits<int>::max();
rollout.search(1, 0);
}
......
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