-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnection.cc
90 lines (70 loc) · 1.34 KB
/
connection.cc
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
#include "connection.hpp"
#include "routing.hpp"
#include "utils.hpp"
#include <algorithm>
#include <iostream>
#include <utility>
#include <boost/none.hpp>
using namespace std;
int connection::counter = 0;
connection::connection(graph &g): m_g(g), m_id(counter++)
{
}
connection::~connection()
{
if (is_established())
tear_down();
}
const demand &
connection::get_demand() const
{
return m_d;
}
bool
connection::is_established() const
{
return m_p != boost::none;
}
int
connection::get_len() const
{
assert(is_established());
boost::property_map<graph, boost::edge_weight_t>::type
wm = get(boost::edge_weight_t(), m_g);
int length = 0;
const path &p = m_p.get().first;
for(const edge &e: p)
length += get(wm, e);
return length;
}
int
connection::get_nol() const
{
assert(is_established());
return m_p.get().first.size();
}
int
connection::get_nsc() const
{
assert(is_established());
return m_p.get().second.size();
}
bool
connection::establish(const demand &d)
{
// Make sure the connection is not established.
assert(!is_established());
// Route the demand.
m_p = routing::route(m_g, d);
// If successful, remember the demand.
if (m_p)
m_d = d;
return is_established();
}
void
connection::tear_down()
{
assert(is_established());
routing::tear_down(m_g, m_p.get());
m_p = boost::none;
}