Commit f460d26b authored by Jonas Seidel's avatar Jonas Seidel

fixing copy and move operations for graph

parent e2499d4b
......@@ -17,15 +17,14 @@ template <typename N, typename E>
void Graph<N,E>::operator=(Graph<N,E>& graph){
std::map<Node<N,E>*, Node<N,E>*> node_lookup;
graph.conditional_bfs_all_components(
[&node_lookup, this](Node<N,E>* node, Edge<N,E>* edge, bool used_in_traversal){
this->add_edge(edge, node_lookup);
},
[&node_lookup, this](Node<N,E>* node){
for(Node<N,E>* node : graph._nodes){
Node<N,E>* new_node = this->add_node(node);
node_lookup.insert({node, new_node});
}
);
}
for(Edge<N,E>* edge : graph._edges){
this->add_edge(edge, node_lookup);
}
}
template <typename N, typename E>
......
......@@ -22,8 +22,12 @@ class Edge{
std::map<E, Attribute> _attributes;
public:
Edge(Edge<N,E>& local_edge) : _description(local_edge._description), _from(local_edge._from), _to(local_edge._to), _attributes(local_edge._attributes) {}
Edge(Edge<N,E>& remote_edge, std::map<Node<N,E>*, Node<N,E>*>& node_lookup) : _description(remote_edge._description), _from(node_lookup.find(remote_edge._from)->second), _to(node_lookup.find(remote_edge._from)->second), _attributes(remote_edge._attributes) {}
Edge(Edge<N,E>&& local_edge) : _description(std::move(local_edge._description)), _from(std::move(local_edge._from)), _to(std::move(local_edge._to)), _attributes(std::move(local_edge._attributes)) {}
Edge(Edge<N,E>& remote_edge, std::map<Node<N,E>*, Node<N,E>*>& node_lookup) : _description(remote_edge._description), _from(node_lookup.find(remote_edge._from)->second), _to(node_lookup.find(remote_edge._to)->second), _attributes(remote_edge._attributes) {
this->_from->add_incident(this);
this->_to->add_incident(this);
}
Edge(Node<N, E>* from, Node<N, E>* to, std::string description = "") : _description(description), _from(from), _to(to){
from->add_incident(this);
to->add_incident(this);
......
......@@ -23,6 +23,8 @@ public:
this->attribute(pair.first).value() = pair.second;
}
}
Node(Node& node) : _description(node.description()), _incident({}), _attributes(node.attributes()) {}
Node(Node&& node) : _description(std::move(node._description)), _incident(std::move(node._incident)), _attributes(std::move(node._attributes)) {}
std::string description(){
if(this->_description == ""){
......
......@@ -3,17 +3,17 @@
Maintenance_Problem::Maintenance_Problem() : Linear_Program(true) {}
Maintenance_Problem::Maintenance_Problem(Maintenance_Problem& mp) : Linear_Program(mp) {
// this->_g = mp._g;
// mp._g = CircSelectNetwork();
this->_g = mp._g;
mp._g = CircSelectNetwork();
}
Maintenance_Problem::Maintenance_Problem(Maintenance_Problem&& mp) : Linear_Program(std::move(mp)) {
// this->_g = std::move(mp._g);
// mp._g = CircSelectNetwork();
this->_g = std::move(mp._g);
mp._g = CircSelectNetwork();
}
Maintenance_Problem::Maintenance_Problem(CircSelectNetwork& g, CircSelectNode* source, CircSelectNode* target, std::set<CircSelectEdge*> critical, size_t intervals)
: Linear_Program(true)//, _g(g)
: Linear_Program(true), _g(g)
{
std::vector<std::pair< std::map<std::pair<CircSelectNode*,CircSelectNodeFields>, std::pair<Variable*, size_t>>, std::map<std::pair<CircSelectEdge*,CircSelectEdgeFields>, std::pair<Variable*, size_t>> >> lookup;
......@@ -105,14 +105,24 @@ Maintenance_Problem::Maintenance_Problem(CircSelectNetwork& g, CircSelectNode* s
this->add_direction_coefficient({target_var.first, 1});
}
CircSelectNetwork& Maintenance_Problem::network(){
return this->_g;
}
void Maintenance_Problem::operator=(Maintenance_Problem& mp){
this->Linear_Program::operator=(mp);
//this->_g = mp._g;
//mp._g = CircSelectNetwork();
this->_g = mp._g;
mp._g = CircSelectNetwork();
}
void Maintenance_Problem::operator=(Maintenance_Problem&& mp){
this->Linear_Program::operator=(mp);
// this->_g = std::move(mp._g);
// mp._g = CircSelectNetwork();
this->_g = std::move(mp._g);
mp._g = CircSelectNetwork();
}
std::ostream& operator<<(std::ostream& os, Maintenance_Problem& mp){
os << mp.network() << std::endl;
os << static_cast<Linear_Program&>(mp) << std::endl;
return os;
}
......@@ -10,15 +10,21 @@
#include "../../Linear_Programming/lp_generator.h"
class Maintenance_Problem : public Linear_Program {
//CircSelectNetwork _g;
CircSelectNetwork _g;
public:
Maintenance_Problem();
Maintenance_Problem(Maintenance_Problem& mp);
Maintenance_Problem(Maintenance_Problem&& mp);
Maintenance_Problem(CircSelectNetwork& g, CircSelectNode* source, CircSelectNode* target, std::set<CircSelectEdge*> critical, size_t intervals);
CircSelectNetwork& network();
void operator=(Maintenance_Problem& mp);
void operator=(Maintenance_Problem&& mp);
friend std::ostream& operator<<(std::ostream& os, Maintenance_Problem& mp);
};
std::ostream& operator<<(std::ostream& os, Maintenance_Problem& mp);
#endif
Markdown is supported
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