OpticalNode.cc (10447:a465576671d4) OpticalNode.cc (10448:bc1a3b7ab5ef)
1/* Copyright (c) 2012 Massachusetts Institute of Technology
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
1
21
22
2#include "model/optical_graph/OpticalNode.h"
3
4namespace DSENT
5{
6 // Set the optical node initial visited num
7 const int OpticalNode::OPTICAL_NODE_INIT_VISITED_NUM = 0;
8
9 OpticalNode::OpticalNode(Type type_, const String& instance_name_, OpticalModel* model_, const WavelengthGroup& wavelengths_)
10 :m_type_(type_), m_instance_name_(instance_name_), m_model_(model_), m_wavelengths_(wavelengths_)
11 {
12 m_loss_ = 0.0;
13 setVisitedNum(OpticalNode::OPTICAL_NODE_INIT_VISITED_NUM);
14 m_downstream_nodes_ = new vector<OpticalNode*>;
15 }
16
17 OpticalNode::~OpticalNode()
18 {
19
20 }
21
22 OpticalNode::Type OpticalNode::getType() const
23 {
24 return m_type_;
25 }
26
27 vector<OpticalNode*>* OpticalNode::getDownstreamNodes() const
28 {
29 return m_downstream_nodes_;
30 }
31
32 const String& OpticalNode::getInstanceName() const
33 {
34 return m_instance_name_;
35 }
36
37 OpticalModel* OpticalNode::getModel()
38 {
39 return m_model_;
40 }
41
42 const OpticalModel* OpticalNode::getModel() const
43 {
44 return (const OpticalModel*) m_model_;
45 }
46
47 void OpticalNode::addDownstreamNode(OpticalNode* node_)
48 {
49 ASSERT(node_->isExpected(getWavelengths()), "[Error] " + getInstanceName() +
50 " -> Downstream node not expecting a superset of the current wavelengths");
51 m_downstream_nodes_->push_back(node_);
52 }
53
54 WavelengthGroup OpticalNode::getWavelengths() const
55 {
56 return m_wavelengths_;
57 }
58
59 bool OpticalNode::isExpected(const WavelengthGroup& wavelengths_) const
60 {
61 // Check that the lower limits are within bounds
62 bool lower_match = (wavelengths_.first >= getWavelengths().first);
63 // Check that the upper limits are within bounds
64 bool upper_match = (wavelengths_.second <= getWavelengths().second);
65 // Assert that there are no misalignments
66 ASSERT(lower_match == upper_match, "[Error] " + getInstanceName() +
67 " -> Wavelength group misalignment!");
68 // Both upper and lower bounds must match
69 return (upper_match && lower_match);
70 }
71
72 //-------------------------------------------------------------------------
73 void OpticalNode::setLoss(double loss_)
74 {
75 m_loss_ = loss_;
76 }
77
78 double OpticalNode::getLoss() const
79 {
80 return m_loss_;
81 }
82
83 void OpticalNode::setVisitedNum(int visited_num_)
84 {
85 m_visited_num_ = visited_num_;
86 }
87
88 int OpticalNode::getVisitedNum() const
89 {
90 return m_visited_num_;
91 }
92 //-------------------------------------------------------------------------
93
94} // namespace DSENT
95
96
23#include "model/optical_graph/OpticalNode.h"
24
25namespace DSENT
26{
27 // Set the optical node initial visited num
28 const int OpticalNode::OPTICAL_NODE_INIT_VISITED_NUM = 0;
29
30 OpticalNode::OpticalNode(Type type_, const String& instance_name_, OpticalModel* model_, const WavelengthGroup& wavelengths_)
31 :m_type_(type_), m_instance_name_(instance_name_), m_model_(model_), m_wavelengths_(wavelengths_)
32 {
33 m_loss_ = 0.0;
34 setVisitedNum(OpticalNode::OPTICAL_NODE_INIT_VISITED_NUM);
35 m_downstream_nodes_ = new vector<OpticalNode*>;
36 }
37
38 OpticalNode::~OpticalNode()
39 {
40
41 }
42
43 OpticalNode::Type OpticalNode::getType() const
44 {
45 return m_type_;
46 }
47
48 vector<OpticalNode*>* OpticalNode::getDownstreamNodes() const
49 {
50 return m_downstream_nodes_;
51 }
52
53 const String& OpticalNode::getInstanceName() const
54 {
55 return m_instance_name_;
56 }
57
58 OpticalModel* OpticalNode::getModel()
59 {
60 return m_model_;
61 }
62
63 const OpticalModel* OpticalNode::getModel() const
64 {
65 return (const OpticalModel*) m_model_;
66 }
67
68 void OpticalNode::addDownstreamNode(OpticalNode* node_)
69 {
70 ASSERT(node_->isExpected(getWavelengths()), "[Error] " + getInstanceName() +
71 " -> Downstream node not expecting a superset of the current wavelengths");
72 m_downstream_nodes_->push_back(node_);
73 }
74
75 WavelengthGroup OpticalNode::getWavelengths() const
76 {
77 return m_wavelengths_;
78 }
79
80 bool OpticalNode::isExpected(const WavelengthGroup& wavelengths_) const
81 {
82 // Check that the lower limits are within bounds
83 bool lower_match = (wavelengths_.first >= getWavelengths().first);
84 // Check that the upper limits are within bounds
85 bool upper_match = (wavelengths_.second <= getWavelengths().second);
86 // Assert that there are no misalignments
87 ASSERT(lower_match == upper_match, "[Error] " + getInstanceName() +
88 " -> Wavelength group misalignment!");
89 // Both upper and lower bounds must match
90 return (upper_match && lower_match);
91 }
92
93 //-------------------------------------------------------------------------
94 void OpticalNode::setLoss(double loss_)
95 {
96 m_loss_ = loss_;
97 }
98
99 double OpticalNode::getLoss() const
100 {
101 return m_loss_;
102 }
103
104 void OpticalNode::setVisitedNum(int visited_num_)
105 {
106 m_visited_num_ = visited_num_;
107 }
108
109 int OpticalNode::getVisitedNum() const
110 {
111 return m_visited_num_;
112 }
113 //-------------------------------------------------------------------------
114
115} // namespace DSENT
116
117