[GIT] ppl/ppl(master): Prefer neg_assign to the use of unary minus on Coefficient objects.

Module: ppl/ppl Branch: master Commit: f1b3b29529f9602a0ea7e36b7a5ae62518e125dc URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=f1b3b29529f96...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Fri Sep 17 16:35:35 2010 +0200
Prefer neg_assign to the use of unary minus on Coefficient objects. Use add_mul_assign even in code only activated during debugging.
---
src/MIP_Problem.cc | 6 +++--- src/PIP_Tree.cc | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/MIP_Problem.cc b/src/MIP_Problem.cc index 33ead88..78e5ff1 100644 --- a/src/MIP_Problem.cc +++ b/src/MIP_Problem.cc @@ -1730,12 +1730,12 @@ PPL::MIP_Problem::compute_generator() const { Coefficient_traits::const_reference t_row_split_var = t_row.get(split_var); if (t_row_split_var > 0) { - split_num = -t_row.get(0); + neg_assign(split_num, t_row.get(0)); split_den = t_row_split_var; } else { split_num = t_row.get(0); - split_den = -t_row_split_var; + neg_assign(split_den, t_row_split_var); } // We compute the lcm to compute subsequently the difference // between the 2 variables. @@ -1808,7 +1808,7 @@ PPL::MIP_Problem::second_phase() { const dimension_type split_var = mapping[i].second; working_cost[original_var] = new_cost[i]; if (mapping[i].second != 0) - working_cost[split_var] = - new_cost[i]; + neg_assign(working_cost[split_var], new_cost[i]); } // Here the first phase problem succeeded with optimum value zero. // Express the old cost function in terms of the computed base. diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc index a5af8f7..2e102d4 100644 --- a/src/PIP_Tree.cc +++ b/src/PIP_Tree.cc @@ -2691,7 +2691,7 @@ PIP_Solution_Node::solve(const PIP_Problem& pip, dimension_type j = 1; for (Variables_Set::const_iterator p = all_params.begin(), p_end = all_params.end(); p != p_end; ++p, ++j) - expr += t_test.get(j) * Variable(*p); + add_mul_assign(expr, t_test.get(j), Variable(*p)); using namespace IO_Operators; std::cerr << "Found mixed parameter sign row: " << best_i << ".\n" << "Solution depends on sign of parameter " @@ -3108,8 +3108,8 @@ PIP_Solution_Node::generate_cut(const dimension_type index, Linear_Expression expr1(ctx1.get(0)); Linear_Expression expr2(ctx2.get(0)); for (dimension_type j = 1; j <= num_params; ++j, ++p) { - expr1 += ctx1.get(j) * Variable(*p); - expr2 += ctx2.get(j) * Variable(*p); + add_mul_assign(expr1, ctx1.get(j), Variable(*p)); + add_mul_assign(expr2, ctx2.get(j), Variable(*p)); } std::cout << "Inserting into context: " << Constraint(expr1 >= 0) << " ; " @@ -3158,9 +3158,9 @@ PIP_Solution_Node::generate_cut(const dimension_type index, dimension_type si = 0; for (dimension_type j = 0; j < space_dimension; ++j) { if (parameters.count(j) == 1) - expr += cut_t.get(ti++) * Variable(j); + add_mul_assign(expr, cut_t.get(ti++), Variable(j)); else - expr += cut_s.get(si++) * Variable(j); + add_mul_assign(expr, cut_s.get(si++), Variable(j)); } std::cout << "Adding cut: " << Constraint(expr + cut_t.get(0) >= 0)
participants (1)
-
Enea Zaffanella