Skip to content

Commit

Permalink
Updated source
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Santini committed Jun 12, 2017
1 parent 306fe08 commit 95e70ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
13 changes: 10 additions & 3 deletions source-code/heuristics/tabu_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace sgcp {
return partitions_colour_status.uncoloured.empty();
}

void TabuSearchSolver::insert(const TabuSearchSolver::InsertionResult& r) {
void TabuSearchSolver::insert(const TabuSearchSolver::InsertionResult& r, uint32_t tenure) {
for(auto v : r.removed_vertices) {
colouring_stable_sets[r.colour].remove_vertex(v);
uncoloured_set.insert(v);
Expand All @@ -163,7 +163,7 @@ namespace sgcp {
partitions_colour_status.uncoloured.erase(r.coloured_partition);
partitions_colour_status.coloured.insert(r.coloured_partition);

tabu_list.insert(std::make_pair(TabuElement{r.colour, r.inserted_vertex}, iteration_n + g.params.tabu_tenure));
tabu_list.insert(std::make_pair(TabuElement{r.colour, r.inserted_vertex}, iteration_n + tenure));

if(all_partitions_coloured()) { solutions.push_back(colouring_stable_sets); }
}
Expand Down Expand Up @@ -204,6 +204,8 @@ namespace sgcp {
std::seed_seq seeds(std::begin(random_data), std::end(random_data));
std::mt19937 mt(seeds);

std::uniform_int_distribution<uint32_t> tenure_dist(g.params.tabu_min_rnd_tenure, g.params.tabu_max_rnd_tenure);

uint32_t max_iterations = g.params.tabu_iterations;

if(g.params.tabu_instance_scaled_iters) {
Expand Down Expand Up @@ -240,8 +242,13 @@ namespace sgcp {
return col_ins_1.second.score < col_ins_2.second.score;
}
);

uint32_t tenure = g.params.tabu_tenure;
if(g.params.tabu_randomised_tenure) {
tenure = tenure_dist(mt);
}

insert(best_insertion_it->second);
insert(best_insertion_it->second, tenure);

if(all_partitions_coloured()) { return solutions; }
else { update_tabu_list(); }
Expand Down
4 changes: 3 additions & 1 deletion source-code/heuristics/tabu_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ namespace sgcp {
InsertionResult simulate_insertion(uint32_t vertex, uint32_t partition, uint32_t colour) const;

// Actually perform the insertion.
void insert(const InsertionResult& r);
// It also puts the corresponding move in the rabu list, for
// the number of iterations specified in ``tenure''.
void insert(const InsertionResult& r, uint32_t tenure);

// Tells wether all partitions have been coloured.
bool all_partitions_coloured() const;
Expand Down
5 changes: 4 additions & 1 deletion source-code/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ namespace sgcp {
mwss_multiplier = tree.get<uint32_t>("mwss_multiplier");

tabu_iterations = tree.get<uint32_t>("tabu.iterations");
tabu_instance_scaled_iters = tree.get<bool>("tabu.instance_scaled_iters");
tabu_tenure = tree.get<uint32_t>("tabu.tenure");
tabu_instance_scaled_iters = tree.get<bool>("tabu.instance_scaled_iters");
tabu_randomised_tenure = tree.get<bool>("tabu.randomised_tenure");
tabu_min_rnd_tenure = tree.get<uint32_t>("tabu.min_randomised_tenure");
tabu_max_rnd_tenure = tree.get<uint32_t>("tabu.max_randomised_tenure");
std::string tabu_score = tree.get<std::string>("tabu.score");

alns_iterations = tree.get<uint32_t>("alns.iterations");
Expand Down
3 changes: 3 additions & 0 deletions source-code/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ namespace sgcp {
uint32_t tabu_iterations;
uint32_t tabu_tenure;
bool tabu_instance_scaled_iters;
bool tabu_randomised_tenure;
uint32_t tabu_min_rnd_tenure;
uint32_t tabu_max_rnd_tenure;
std::string tabu_score;

uint32_t alns_iterations;
Expand Down

0 comments on commit 95e70ad

Please sign in to comment.