Skip to content

Commit

Permalink
Added max time duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukáš Plevač committed Apr 28, 2022
1 parent ffd8b8e commit 83715c9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ options:
-max_abs_error=num maximal accepted abs error of circuic (all combinations)
-cross_parts=2..inf number of crossover points for cross individuals
-l-back number for mutation. how many back gates can use this gate
-status show complete generations ids and best loss
-profile for profile extesion print data in format {tranzistros}-{output error}-{score};
-max_duration=1..inf maximal time duration of optimalization in minutes
-representation={aig, gates, mig} reprezenation of circuic for CGP
```
Expand Down
42 changes: 39 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <fstream>
#include <stdexcept>
#include <regex>
//timer
#include <chrono>

//representations
#include "aig.h"
Expand Down Expand Up @@ -63,7 +65,8 @@ struct cgploss : public Pass {
unsigned param_parrents_count = 1;
unsigned param_cross_parts = 4;
unsigned param_l_back = 0;
unsigned param_status = false;
bool param_status = false;
unsigned param_max_duration = 0;
std::string config_file = "";
std::string param_repres = "aig";

Expand All @@ -88,6 +91,20 @@ struct cgploss : public Pass {
param_selection_count = stoi(parsed);
}

if (param_selection_count < 1) {
log("[ERROR] Bad value for -selection_size, min value is 1. using 1\n");
param_selection_count = 1;
}

} else if (param.rfind("-max_duration=", 0) == 0) {
auto parsed = param.substr(std::string("-max_duration=").length());

if (!config::parse::is_number(parsed)) {
log("[ERROR] Bad value for -max_duration using default\n");
} else {
param_max_duration = stoi(parsed);
}

} else if (param.rfind("-generation_size=", 0) == 0) {
auto parsed = param.substr(std::string("-generation_size=").length());

Expand All @@ -97,6 +114,11 @@ struct cgploss : public Pass {
param_generation_size = stoi(parsed);
}

if (param_generation_size < 2) {
log("[ERROR] Bad value for -generation_size, min value is 2. using 2\n");
param_generation_size = 2;
}

} else if (param.rfind("-max_one_error=", 0) == 0) {
auto parsed = param.substr(std::string("-max_one_error=").length());

Expand Down Expand Up @@ -268,8 +290,9 @@ struct cgploss : public Pass {

debug_indiv_to_file(debug_indiv_file, repres);

auto generation = new evolution::generation(repres, param_max_one_loss, param_max_abs_loss, param_power_accuracy_ratio);
auto parrent0 = generation->add_individual(repres->clone());
auto generation = new evolution::generation(repres, param_max_one_loss, param_max_abs_loss, param_power_accuracy_ratio);
auto parrent0 = generation->add_individual(repres->clone());
auto timer_start = std::chrono::high_resolution_clock::now();

//create generation using clone
for (unsigned i = 0; i < param_generation_size; i++) {
Expand Down Expand Up @@ -314,6 +337,19 @@ struct cgploss : public Pass {
auto p_loss = generation->individuals[0].repres->power_loss();
log("%i-%f-%f;", p_loss, generation->individuals[0].score - (p_loss * param_power_accuracy_ratio), generation->individuals[0].score);
}

if (param_max_duration > 0) {
auto timer_stop = std::chrono::high_resolution_clock::now();
auto act_duration = std::chrono::duration_cast<std::chrono::minutes>(timer_stop - timer_start);

if (act_duration.count() >= param_max_duration) {
if (param_status) {
log("[INFO] maximal duration reached\n");
}

break;
}
}
}

repres = generation->individuals[0].repres->clone();
Expand Down

0 comments on commit 83715c9

Please sign in to comment.