OpticalNode.cc revision 10447:a465576671d4
1
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
97