/// ideal spacing between two columns
struct Idealspacing {
- /// the ideal distance
- Real space_f_;
+ /// the ideal distance
+ Real space_f_;
- /// Hooke's constant: how strong are the "springs" attached to columns
- Real hooke_f_;
+ /// Hooke's constant: how strong are the "springs" attached to columns
+ Real hooke_f_;
- /// the two columns
- int left_i_;
- int right_i_;
+ /// the two columns
+ int left_i_;
+ int right_i_;
- void print() const;
- void OK() const ;
- Idealspacing();
+ Real energy_f (Real x) const;
+ void print() const;
+ void OK() const ;
+ Idealspacing();
};
Score_column* scol_l (int);
void connect (int i,int j, Real,Real);
Line_of_cols error_pcol_l_arr() const;
+ Real calculate_energy_f (Vector) const;
public:
static Line_spacer *constructor();
}
}
+
+Real
+Spring_spacer::calculate_energy_f (Vector solution) const
+{
+ Real e = 0.0;
+ for (PCursor<Idealspacing*> i (ideal_p_list_.top()); i.ok(); i++)
+ {
+ e += i->energy_f(solution(i->right_i_) - solution(i->left_i_));
+ }
+
+ return e;
+}
void
Spring_spacer::lower_bound_solution (Col_hpositions*positions) const
{
start.fill (0.0);
Vector solution_vec (lp.solve (start));
- positions->energy_f_ = lp.eval (solution_vec);
+ positions->energy_f_ = calculate_energy_f (solution_vec);
positions->config = solution_vec;
positions->satisfies_constraints_b_ = check_constraints (solution_vec);
}
WARN << "solution doesn't satisfy constraints.\n" ;
}
position_loose_cols (solution_vec);
- positions->energy_f_ = lp.eval (solution_vec);
+ positions->energy_f_ = calculate_energy_f (solution_vec);
positions->config = solution_vec;
positions->error_col_l_arr_ = error_pcol_l_arr();