-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimum_deflection.H
More file actions
154 lines (141 loc) · 6.4 KB
/
minimum_deflection.H
File metadata and controls
154 lines (141 loc) · 6.4 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# ifndef MINIMUM_DEFLECTION_H
# define MINIMUM_DEFLECTION_H
# include <grid.H>
# include <package.H>
# include <statistics.H>
/**
* \brief Clase que contiene el algoritmo de deflección mínima.
* @authors Alejandro Mujica, Anna Lezama
*/
class Minimum_Deflection
{
public:
/**
* Operación que ejecuta el enrutamiento por deflección mínima.
* @param g La malla en la que se est&aaccute; trabajando.
* @param node El nodo donde se encuentran los paquetes que se desean enrutar.
*/
void operator()(Grid & g, Grid::Node * node)
{
if (node->get_clients_list().is_empty())
return;
g.reset_all_arcs();
Statistics * statistics = Statistics::get_instance();
std::string node_name = node->to_string();
DynDlist<Package *> & list = node->get_clients_list();
int i = 1;
for (DynDlist<Package *>::Iterator it(list); not list.is_empty(); )
{
if (not it.has_current())
{
it.reset_first();
++i;
}
Package *& curr_package = it.get_current();
if (i > 2)
{
Grid::Arc * first_free_link = g.get_first_free_link(node);
Grid::Node * tgt = g.get_connected_node(first_free_link, node);
curr_package->rout_to(tgt);
g.set_arc_busy_for_node(first_free_link, node, curr_package);
curr_package->inc_ttl();
it.next();
curr_package->inc_num_deflections();
node->inc_num_nodes_deflected();
statistics->set_max_deflections(curr_package->get_num_deflections());
list.remove(curr_package);
std::string pkn = curr_package->to_string();
std::string tgt_name = tgt->to_string();
std::string stp = gnu::autosprintf("%s es deflectado de %s a %s",
pkn.c_str(), node_name.c_str(), tgt_name.c_str());
std::string stn = gnu::autosprintf("%s ha deflectado al paquete %s hacia %s",
node_name.c_str(), pkn.c_str(), tgt_name.c_str());
statistics->add_statistic_to_package(pkn, stp);
statistics->add_statistic_to_node(node_name, stn);
continue;
}
if (curr_package->get_num_favorable_directions() != i)
{
it.next();
continue;
}
if (i == 1)
{
Direction favorable_direction = curr_package->get_h_favorable_direction() != Num_Directions ?
curr_package->get_h_favorable_direction() :
curr_package->get_v_favorable_direction();
Grid::Arc * link = g.get_arc_by_rout(node, favorable_direction);
if (not link or g.is_arc_busy_for_node(link, node))
{
it.next();
continue;
}
Grid::Node * tgt = g.get_connected_node(link, node);
curr_package->rout_to(tgt);
g.set_arc_busy_for_node(link, node, curr_package);
curr_package->inc_ttl();
curr_package->inc_num_routings();
node->inc_num_nodes_routed();
it.next();
list.remove(curr_package);
std::string pkn = curr_package->to_string();
std::string tgt_name = tgt->to_string();
std::string stp = gnu::autosprintf("%s es enrutado de %s a %s",
pkn.c_str(), node_name.c_str(), tgt_name.c_str());
std::string stn = gnu::autosprintf("%s ha enrutado al paquete %s hacia %s",
node_name.c_str(), pkn.c_str(), tgt_name.c_str());
statistics->add_statistic_to_package(pkn, stp);
statistics->add_statistic_to_node(node_name, stn);
}
else
{
Direction favorable_direction = curr_package->get_h_favorable_direction();
Grid::Arc * link = g.get_arc_by_rout(node, favorable_direction);
if (link and not g.is_arc_busy_for_node(link, node))
{
Grid::Node * tgt = g.get_connected_node(link, node);
curr_package->rout_to(tgt);
g.set_arc_busy_for_node(link, node, curr_package);
curr_package->inc_ttl();
curr_package->inc_num_routings();
node->inc_num_nodes_routed();
it.next();
list.remove(curr_package);
std::string pkn = curr_package->to_string();
std::string tgt_name = tgt->to_string();
std::string stp = gnu::autosprintf("%s es enrutado de %s a %s", pkn.c_str(),
node_name.c_str(), tgt_name.c_str());
std::string stn = gnu::autosprintf("%s ha enrutado al paquete %s hacia %s",
node_name.c_str(), pkn.c_str(), tgt_name.c_str());
statistics->add_statistic_to_package(pkn, stp);
statistics->add_statistic_to_node(node_name, stn);
continue;
}
favorable_direction = curr_package->get_v_favorable_direction();
link = g.get_arc_by_rout(node, favorable_direction);
if (not link or g.is_arc_busy_for_node(link, node))
{
it.next();
continue;
}
Grid::Node * tgt = g.get_connected_node(link, node);
curr_package->rout_to(tgt);
g.set_arc_busy_for_node(link, node, curr_package);
curr_package->inc_ttl();
curr_package->inc_num_routings();
node->inc_num_nodes_routed();
it.next();
std::string pkn = curr_package->to_string();
std::string tgt_name = tgt->to_string();
std::string stp = gnu::autosprintf("%s es enrutado de %s a %s",
pkn.c_str(), node_name.c_str(), tgt_name.c_str());
std::string stn = gnu::autosprintf("%s ha enrutado al paquete %s hacia %s",
node_name.c_str(), pkn.c_str(), tgt_name.c_str());
statistics->add_statistic_to_package(pkn, stp);
statistics->add_statistic_to_node(node_name, stn);
list.remove(curr_package);
}
}
}
};
# endif //MINIMUM_DEFLECTION_H