maintenance_problem_generator.cpp 1.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include "maintenance_problem_generator.h"

maintenance_problem_generator::maintenance_problem_generator(random_graph_generator<CircSelectNodeFields, CircSelectEdgeFields> graph_generator, size_t number_of_critical_edges, size_t length_of_interval)
  : _graph_generator(graph_generator), _number_of_critical_edges(number_of_critical_edges), _length_of_interval(length_of_interval) {}

Maintenance_Problem maintenance_problem_generator::next(){
  std::pair<std::pair<CircSelectNode*,CircSelectNode*>, CircSelectNetwork> stg = this->_graph_generator.next_acyclic_2_tips();

  std::set<CircSelectEdge*> critical_edges;
  random_set_element_generator<CircSelectEdge*> set_gen (&stg.second.edges());
  for(size_t i = 0; i < this->_number_of_critical_edges; i++){
    CircSelectEdge* curr = set_gen.next();
    while(critical_edges.find(curr) != critical_edges.end()){
      set_gen >> curr;
    }

    critical_edges.insert(curr);
    curr->attribute(Critical).value() = true;
  }

  return Maintenance_Problem(stg.second, stg.first.first, stg.first.second, critical_edges, this->_length_of_interval);
}

void maintenance_problem_generator::operator>>(Maintenance_Problem& mp){
  mp = this->next();
}