-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alberto-santini
committed
Oct 27, 2017
1 parent
209d04c
commit f902a3a
Showing
16 changed files
with
186 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// Created by alberto on 14/09/17. | ||
// | ||
|
||
#include "alns_stats.h" | ||
|
||
#include <iostream> | ||
#include <cassert> | ||
|
||
namespace sgcp { | ||
void ALNSStats::print_stats() { | ||
compute_maps(); | ||
|
||
std::cout << "Repair methods:" << std::endl; | ||
for (auto [key, val] : repair_pct_accept) { | ||
std::cout << key << ", " << val << std::endl; | ||
} | ||
std::cout << "Destroy methods:" << std::endl; | ||
for (auto [key, val] : destroy_pct_accept) { | ||
std::cout << key << ", " << val << std::endl; | ||
} | ||
} | ||
|
||
void ALNSStats::compute_maps() { | ||
assert(repair_methods.size() == destroy_methods.size()); | ||
assert(accepted.size() == destroy_methods.size()); | ||
|
||
auto has_key = [] (const auto& map, uint32_t key) -> bool { | ||
return map.find(key) != map.end(); | ||
}; | ||
|
||
auto set_val = [&has_key] (auto& map, uint32_t key, float val) -> void { | ||
if (!has_key(map, key)) { map[key] = 0.0f; } | ||
map[key] += val; | ||
}; | ||
|
||
std::map<uint32_t, float> destroy_tot; | ||
std::map<uint32_t, float> repair_tot; | ||
|
||
for (auto i = 0u; i < accepted.size(); ++i) { | ||
auto destroy = destroy_methods[i]; | ||
auto repair = repair_methods[i]; | ||
|
||
set_val(destroy_tot, destroy, 1.0); | ||
set_val(repair_tot, repair, 1.0); | ||
|
||
if (accepted[i]) { | ||
set_val(destroy_pct_accept, destroy, 1.0); | ||
set_val(repair_pct_accept, repair, 1.0); | ||
} | ||
} | ||
|
||
for(auto [key, val] : destroy_pct_accept) { | ||
std::cout << "destroy method " << key << " was called " << destroy_tot[key] << " times, and the solution was accepted " << val << " times." << std::endl; | ||
destroy_pct_accept[key] = val / destroy_tot[key]; | ||
} | ||
|
||
for(auto [key, val] : repair_pct_accept) { | ||
std::cout << "repair method " << key << " was called " << repair_tot[key] << " times, and the solution was accepted " << val << " times." << std::endl; | ||
repair_pct_accept[key] = val / repair_tot[key]; | ||
} | ||
} | ||
|
||
void ALNSStats::add_destroy(uint32_t method_id) { | ||
destroy_methods.push_back(method_id); | ||
} | ||
|
||
void ALNSStats::add_repair(uint32_t method_id) { | ||
repair_methods.push_back(method_id); | ||
} | ||
|
||
void ALNSStats::add_accepted() { | ||
accepted.push_back(true); | ||
} | ||
|
||
void ALNSStats::add_rejected() { | ||
accepted.push_back(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Created by alberto on 14/09/17. | ||
// | ||
|
||
#ifndef SGCP_ALNS_STATS_H | ||
#define SGCP_ALNS_STATS_H | ||
|
||
#include <vector> | ||
#include <map> | ||
#include <cstdint> | ||
|
||
namespace sgcp { | ||
class ALNSStats { | ||
std::vector<uint32_t> destroy_methods; | ||
std::vector<uint32_t> repair_methods; | ||
std::vector<bool> accepted; | ||
std::map<uint32_t, float> destroy_pct_accept; | ||
std::map<uint32_t, float> repair_pct_accept; | ||
|
||
void compute_maps(); | ||
|
||
public: | ||
void add_destroy(uint32_t method_id); | ||
void add_repair(uint32_t method_id); | ||
void add_accepted(); | ||
void add_rejected(); | ||
void print_stats(); | ||
}; | ||
} | ||
|
||
#endif //SGCP_ALNS_STATS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.