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 */
21
22
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
118