-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprod-plan-graph.H
More file actions
135 lines (101 loc) · 3.04 KB
/
Copy pathprod-plan-graph.H
File metadata and controls
135 lines (101 loc) · 3.04 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# ifndef PRODPLANGRAPH_H
# define PRODPLANGRAPH_H
# include <htlist.H>
# include <tpl_dynListQueue.H>
# include <tpl_dynSetTree.H>
# include <tpl_agraph.H>
# include <net.H>
using namespace std;
using namespace Aleph;
struct NodeInfo
{
void * product;
double quantity;
Planta * plant = nullptr;
bool is_in_queue = false;
enum class ProductType { Product, Input } type;
NodeInfo(void * p, double q, ProductType t = ProductType::Product)
: product(p), quantity(q), type(t)
{
// Empty
}
string get_cmp_key() const;
Uid get_id() const;
const string & get_name() const;
bool operator == (const NodeInfo & info) const
{
return info.product == product;
}
friend ostream & operator << (ostream & out, const NodeInfo & info)
{
out << info.get_name() << "\\n" << info.quantity << "\\n"
<< (info.plant == nullptr ? "New plant" : info.plant->nombre);
return out;
}
};
using PPNode = Graph_Anode<NodeInfo>;
using PPArc = Graph_Aarc<double>; // double for quantity in relationship
using PPGraph = Array_Graph<PPNode, PPArc>;
using ProducerSet = DynSetTree<Productor *, Treap>;
/* plant, capacity (available quantity) */
using PlantCap = tuple<Planta *, double>;
struct CmpPlantCap
{
bool operator () (const PlantCap & a, const PlantCap & b) const
{
return get<0>(a) < get<0>(b);
}
};
using PlantTable = DynSetTree<PlantCap, Treap, CmpPlantCap>;
using ProductMap = DynMapTreap<MetaProducto *, PlantCap *>;
using PlantMap = DynMapTreap<string, ProductMap>;
using ClassPlantSet = tuple<PlantMap, PlantTable>;
struct CmpNetArcs
{
bool operator () (Net::Arc * a1, Net::Arc * a2) const
{
return a1->get_info().arco_id < a2->get_info().arco_id;
}
};
struct CmpPPNodes
{
bool operator () (PPNode * p, PPNode * q) const
{
return p->get_info().get_cmp_key() < q->get_info().get_cmp_key();
}
};
struct CmpPPArcs
{
bool operator () (PPArc * a1, PPArc * a2) const
{
if (a1->src_node < a2->src_node)
return true;
return not (a2->src_node < a1->src_node) and a1->tgt_node < a2->tgt_node;
}
};
using NetArcsIdx = DynSetTreap<Net::Arc *, CmpNetArcs>;
using PPNodesIdx = DynSetTreap<PPGraph::Node *, CmpPPNodes>;
using PPArcsIdx = DynSetTreap<PPGraph::Arc *, CmpPPArcs>;
struct ProdPlanGraph : PPGraph
{
using PPGraph::PPGraph;
MetaMapa * map;
ProdPlanGraph(MetaMapa * m = nullptr)
: PPGraph(), map(m)
{
// Empty
}
Net::Arc * search_net_arc(NetArcsIdx &, Uid);
tuple<Node *, double>
create_node_and_connect(void *, double, NodeInfo::ProductType, Node *,
PPNodesIdx &, PPArcsIdx &, ClassPlantSet &, double);
void build_pp(DynList<pair<MetaProducto *, double>> &, size_t,
ProducerSet &);
void build_pp(DynList<pair<MetaProducto *, double>> &, size_t);
private:
/// Builds a production plan with a breadth first algorithm.
void build_pp(MetaProducto *, double, size_t, NetArcsIdx &,
ClassPlantSet &, PPNodesIdx &, PPArcsIdx &);
ClassPlantSet classify_plants(ProducerSet &);
};
# endif // PRODPLANGRAPH_H