1 /* Copyright (c) 2012 Massachusetts Institute of Technology
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
23 #include "model/optical_graph/OpticalNode.h"
27 // Set the optical node initial visited num
28 const int OpticalNode::OPTICAL_NODE_INIT_VISITED_NUM
= 0;
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_
)
34 setVisitedNum(OpticalNode::OPTICAL_NODE_INIT_VISITED_NUM
);
35 m_downstream_nodes_
= new vector
<OpticalNode
*>;
38 OpticalNode::~OpticalNode()
43 OpticalNode::Type
OpticalNode::getType() const
48 vector
<OpticalNode
*>* OpticalNode::getDownstreamNodes() const
50 return m_downstream_nodes_
;
53 const String
& OpticalNode::getInstanceName() const
55 return m_instance_name_
;
58 OpticalModel
* OpticalNode::getModel()
63 const OpticalModel
* OpticalNode::getModel() const
65 return (const OpticalModel
*) m_model_
;
68 void OpticalNode::addDownstreamNode(OpticalNode
* node_
)
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_
);
75 WavelengthGroup
OpticalNode::getWavelengths() const
77 return m_wavelengths_
;
80 bool OpticalNode::isExpected(const WavelengthGroup
& wavelengths_
) const
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
);
93 //-------------------------------------------------------------------------
94 void OpticalNode::setLoss(double loss_
)
99 double OpticalNode::getLoss() const
104 void OpticalNode::setVisitedNum(int visited_num_
)
106 m_visited_num_
= visited_num_
;
109 int OpticalNode::getVisitedNum() const
111 return m_visited_num_
;
113 //-------------------------------------------------------------------------