[GIT] ppl/ppl(master): Got rid of non-const PIP_Tree_Node as_decision() and as_solution() methods.

Module: ppl/ppl Branch: master Commit: 28dc8bb7f4c03855c8581516b3948650bea22e3b URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=28dc8bb7f4c03...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Sat Feb 20 12:30:19 2010 +0100
Got rid of non-const PIP_Tree_Node as_decision() and as_solution() methods.
---
src/PIP_Problem.cc | 14 ++++++++------ src/PIP_Tree.cc | 48 ++++++++++++++++-------------------------------- src/PIP_Tree.defs.hh | 12 ------------ 3 files changed, 24 insertions(+), 50 deletions(-)
diff --git a/src/PIP_Problem.cc b/src/PIP_Problem.cc index ad234eb..8dbae6d 100644 --- a/src/PIP_Problem.cc +++ b/src/PIP_Problem.cc @@ -352,12 +352,12 @@ PPL::PIP_Problem::ascii_dump(std::ostream& s) const { s << "\ncurrent_solution: "; if (current_solution == 0) s << "BOTTOM\n"; - else if (PIP_Decision_Node* dec = current_solution->as_decision()) { + else if (const PIP_Decision_Node* dec = current_solution->as_decision()) { s << "DECISION\n"; dec->ascii_dump(s); } else { - PIP_Solution_Node* sol = current_solution->as_solution(); + const PIP_Solution_Node* sol = current_solution->as_solution(); PPL_ASSERT(sol != 0); s << "SOLUTION\n"; sol->ascii_dump(s); @@ -470,13 +470,15 @@ PPL::PIP_Problem::ascii_load(std::istream& s) { if (str == "BOTTOM") current_solution = 0; else if (str == "DECISION") { - current_solution = new PIP_Decision_Node(0, 0); - if (!current_solution->as_decision()->ascii_load(s)) + PIP_Decision_Node* dec = new PIP_Decision_Node(0, 0); + current_solution = dec; + if (!dec->ascii_load(s)) return false; } else if (str == "SOLUTION") { - current_solution = new PIP_Solution_Node(); - if (!current_solution->as_solution()->ascii_load(s)) + PIP_Solution_Node* sol = new PIP_Solution_Node; + current_solution = sol; + if (!sol->ascii_load(s)) return false; } else diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc index deaeb15..ee05538 100644 --- a/src/PIP_Tree.cc +++ b/src/PIP_Tree.cc @@ -423,41 +423,21 @@ PIP_Tree_Node::as_solution() const { return 0; }
-PIP_Solution_Node* -PIP_Tree_Node::as_solution() { - return 0; -} - const PIP_Decision_Node* PIP_Tree_Node::as_decision() const { return 0; }
-PIP_Decision_Node* -PIP_Tree_Node::as_decision() { - return 0; -} - const PIP_Solution_Node* PIP_Solution_Node::as_solution() const { return this; }
-PIP_Solution_Node* -PIP_Solution_Node::as_solution() { - return this; -} - const PIP_Decision_Node* PIP_Decision_Node::as_decision() const { return this; }
-PIP_Decision_Node* -PIP_Decision_Node::as_decision() { - return this; -} - dimension_type PIP_Tree_Node::insert_artificials(Variables_Set& params, const dimension_type space_dimension) const { @@ -708,12 +688,12 @@ PIP_Decision_Node::ascii_dump(std::ostream& s) const { s << "\ntrue_child: "; if (true_child == 0) s << "BOTTOM\n"; - else if (PIP_Decision_Node* dec = true_child->as_decision()) { + else if (const PIP_Decision_Node* dec = true_child->as_decision()) { s << "DECISION\n"; dec->ascii_dump(s); } else { - PIP_Solution_Node* sol = true_child->as_solution(); + const PIP_Solution_Node* sol = true_child->as_solution(); PPL_ASSERT(sol != 0); s << "SOLUTION\n"; sol->ascii_dump(s); @@ -723,12 +703,12 @@ PIP_Decision_Node::ascii_dump(std::ostream& s) const { s << "\nfalse_child: "; if (false_child == 0) s << "BOTTOM\n"; - else if (PIP_Decision_Node* dec = false_child->as_decision()) { + else if (const PIP_Decision_Node* dec = false_child->as_decision()) { s << "DECISION\n"; dec->ascii_dump(s); } else { - PIP_Solution_Node* sol = false_child->as_solution(); + const PIP_Solution_Node* sol = false_child->as_solution(); PPL_ASSERT(sol != 0); s << "SOLUTION\n"; sol->ascii_dump(s); @@ -755,13 +735,15 @@ PIP_Decision_Node::ascii_load(std::istream& s) { if (str == "BOTTOM") true_child = 0; else if (str == "DECISION") { - true_child = new PIP_Decision_Node(0, 0); - if (!true_child->as_decision()->ascii_load(s)) + PIP_Decision_Node* dec = new PIP_Decision_Node(0, 0); + true_child = dec; + if (!dec->ascii_load(s)) return false; } else if (str == "SOLUTION") { - true_child = new PIP_Solution_Node(); - if (!true_child->as_solution()->ascii_load(s)) + PIP_Solution_Node* sol = new PIP_Solution_Node; + true_child = sol; + if (!sol->ascii_load(s)) return false; } else @@ -780,13 +762,15 @@ PIP_Decision_Node::ascii_load(std::istream& s) { if (str == "BOTTOM") false_child = 0; else if (str == "DECISION") { - false_child = new PIP_Decision_Node(0, 0); - if (!false_child->as_decision()->ascii_load(s)) + PIP_Decision_Node* dec = new PIP_Decision_Node(0, 0); + false_child = dec; + if (!dec->ascii_load(s)) return false; } else if (str == "SOLUTION") { - false_child = new PIP_Solution_Node(); - if (!false_child->as_solution()->ascii_load(s)) + PIP_Solution_Node* sol = new PIP_Solution_Node; + false_child = sol; + if (!sol->ascii_load(s)) return false; } else diff --git a/src/PIP_Tree.defs.hh b/src/PIP_Tree.defs.hh index a8cc6a9..12b1292 100644 --- a/src/PIP_Tree.defs.hh +++ b/src/PIP_Tree.defs.hh @@ -64,15 +64,9 @@ public: //! Returns \p this if \p *this is a solution node, 0 otherwise. virtual const PIP_Solution_Node* as_solution() const;
- //! Returns \p this if \p *this is a solution node, 0 otherwise. - virtual PIP_Solution_Node* as_solution(); - //! Returns \p this if \p *this is a decision node, 0 otherwise. virtual const PIP_Decision_Node* as_decision() const;
- //! Returns \p this if \p *this is a decision node, 0 otherwise. - virtual PIP_Decision_Node* as_decision(); - /*! \brief Returns the system of parameter constraints controlling \p *this.
@@ -327,9 +321,6 @@ public: //! Returns \p this. virtual const PIP_Solution_Node* as_solution() const;
- //! Returns \p this. - virtual PIP_Solution_Node* as_solution(); - //! Prints on \p s the tree rooted in \p *this. virtual void print_tree(std::ostream& s, unsigned indent, @@ -694,9 +685,6 @@ public: //! Returns \p this. virtual const PIP_Decision_Node* as_decision() const;
- //! Returns \p this. - virtual PIP_Decision_Node* as_decision(); - //! Returns a const pointer to the \p b (true or false) branch of \p *this. const PIP_Tree_Node* child_node(bool b) const;
participants (1)
-
Enea Zaffanella