Louis BECQUEY

More verbose about the searching zones

......@@ -107,8 +107,8 @@ MOIP::MOIP(const RNA& rna, const vector<Motif>& insertionSites, uint nsets, floa
// obj1 += IloNum(insertion_sites_[i].score) * insertion_dv_[index_of_first_components[i]];
// RNA MoIP style
IloNum sum_k= 0;
for(const Component& c : insertion_sites_[i].comp) sum_k += c.k;
IloNum sum_k = 0;
for (const Component& c : insertion_sites_[i].comp) sum_k += c.k;
obj1 += IloNum(sum_k * sum_k) * insertion_dv_[index_of_first_components[i]];
}
......@@ -133,7 +133,7 @@ bool MOIP::is_undominated_yet(const SecondaryStructure& s)
return true;
}
SecondaryStructure MOIP::solve_objective(int o, double min, double max)
SecondaryStructure MOIP::solve_objective(int o, double min, double max, bool below)
{
// Solves one of the objectives, under constraint that the other should be in [min, max]
......@@ -144,19 +144,25 @@ SecondaryStructure MOIP::solve_objective(int o, double min, double max)
max = max - min;
}
if (verbose_)
cout << std::setprecision(8) << "\nSolving objective function " << o << ", " << min << " <= Obj" << 3 - o
<< " <= " << max << "..." << endl;
if (verbose_) {
cout << std::setprecision(8) << "\nSolving objective function " << o << ", ";
if (below)
cout << "below " << max;
else
cout << "on top of " << min;
cout << ": Obj" << 3 - o << " being in [" << min - precision_ << ", " << max + precision_ << "]..." << endl;
}
IloObjective obj;
IloRange bounds;
// gather known solutions in the search zone to forbid them
if (verbose_)
cout << "\t>forbidding solutions found in [" << std::setprecision(10) << (min) << ", " << (max) << ']' << endl;
vector<IloConstraint> F;
for (const SecondaryStructure& prev : pareto_)
if ((min - 2.0 * precision_) <= prev.get_objective_score(3 - o) and prev.get_objective_score(3 - o) <= (max + precision_ * 2.0)) {
if ((min) <= prev.get_objective_score(3 - o) and prev.get_objective_score(3 - o) <= (max)) {
F.push_back(prev.forbid_this_);
if (verbose_) cout << "\t\t>forbidding " << prev.to_string() << endl;
// if (verbose_) cout << "\t\t>forbidding " << prev.to_string() << endl;
}
if (verbose_) cout << "\t>forbidding " << F.size() << " solutions already found in that zone" << endl;
......@@ -392,9 +398,9 @@ void MOIP::define_problem_constraints(void)
}
}
void MOIP::search_between(double lambdaMin, double lambdaMax)
void MOIP::search_between(double lambdaMin, double lambdaMax, bool below)
{
SecondaryStructure s = solve_objective(obj_to_solve_, lambdaMin, lambdaMax);
SecondaryStructure s = solve_objective(obj_to_solve_, lambdaMin, lambdaMax, below);
if (!s.is_empty_structure) { // A solution has been found
// Attribute the correct pareto set label
......@@ -430,31 +436,34 @@ void MOIP::search_between(double lambdaMin, double lambdaMax)
x->set_pareto_set(k + 1);
} else {
if (verbose_)
cout << "\t>removing structure from Pareto set " << k << ":\t" << x->to_string() << endl;
cout << "\t>removing structure from Pareto set " << k << ":\tobj" << 3 - obj_to_solve_
<< '=' << x->get_objective_score(3 - obj_to_solve_) << endl;
pareto_.erase(x);
}
}
if (exists_horizontal_outdated_labels(s))
for (vector<SecondaryStructure>::iterator x = pareto_.end() - 2; x >= pareto_.begin(); x--)
if (
abs(x->get_objective_score(3 - obj_to_solve_) - s.get_objective_score(3 - obj_to_solve_)) < precision_ and
precision_ < s.get_objective_score(obj_to_solve_) - x->get_objective_score(obj_to_solve_)) {
uint k = x->get_pareto_set();
if (k <= n_sets_) {
if (verbose_)
cout << "\t>moving a structure from Pareto set " << k << " to " << k + 1 << endl;
x->set_pareto_set(k + 1);
} else {
if (verbose_)
cout << "\t>removing structure from Pareto set " << k << ":\t" << x->to_string() << endl;
pareto_.erase(x);
}
}
// if (exists_horizontal_outdated_labels(s))
// for (vector<SecondaryStructure>::iterator x = pareto_.end() - 2; x >= pareto_.begin(); x--)
// if (
// abs(x->get_objective_score(3 - obj_to_solve_) - s.get_objective_score(3 - obj_to_solve_)) < precision_ and
// precision_ < s.get_objective_score(obj_to_solve_) - x->get_objective_score(obj_to_solve_)) {
// uint k = x->get_pareto_set();
// if (k <= n_sets_) {
// if (verbose_)
// cout << "\t>moving a structure from Pareto set " << k << " to " << k + 1 << endl;
// x->set_pareto_set(k + 1);
// } else {
// if (verbose_)
// cout << "\t>removing structure from Pareto set " << k << ":\tobj" << 3 - obj_to_solve_
// << '=' << x->get_objective_score(3 - obj_to_solve_) << endl;
// pareto_.erase(x);
// }
// }
// search below and on top of s
search_between(s.get_objective_score(3 - obj_to_solve_) + epsilon_, lambdaMax);
if (s.get_pareto_set() <= n_sets_) search_between(lambdaMin, s.get_objective_score(3 - obj_to_solve_));
search_between(s.get_objective_score(3 - obj_to_solve_) + epsilon_, lambdaMax, false);
if (s.get_pareto_set() <= n_sets_)
search_between(lambdaMin, s.get_objective_score(3 - obj_to_solve_), true);
} else {
if (verbose_) cout << "\t>solution ignored." << endl;
......
......@@ -16,11 +16,11 @@ class MOIP
MOIP(void);
MOIP(const RNA& rna, const vector<Motif>& motifSites, uint nsets, float pthreshold, bool verbose);
~MOIP(void);
SecondaryStructure solve_objective(int o, double min, double max);
SecondaryStructure solve_objective(int o, double min, double max, bool below);
SecondaryStructure solve_objective(int o);
uint get_n_solutions(void) const;
const SecondaryStructure& solution(uint i) const;
void search_between(double lambdaMin, double lambdaMax);
void search_between(double lambdaMin, double lambdaMax, bool below);
bool allowed_basepair(size_t u, size_t v) const;
void add_solution(const SecondaryStructure& s);
void remove_solution(uint i);
......@@ -66,5 +66,5 @@ inline uint MOIP::get_n_solutions(void) const { return pare
inline const SecondaryStructure& MOIP::solution(uint i) const { return pareto_[i]; }
inline IloNumExprArg& MOIP::y(size_t u, size_t v) { return basepair_dv_[get_yuv_index(u, v)]; }
inline IloNumExprArg& MOIP::C(size_t x, size_t i) { return insertion_dv_[get_Cpxi_index(x, i)]; }
inline SecondaryStructure MOIP::solve_objective(int o) { return solve_objective(o, 0, rna_.get_RNA_length()); }
inline SecondaryStructure MOIP::solve_objective(int o) { return solve_objective(o, 0, rna_.get_RNA_length(), false); }
#endif // MOIP_H_
\ No newline at end of file
......
......@@ -118,12 +118,10 @@ int main(int argc, char* argv[])
MOIP myMOIP = MOIP(myRNA, posInsertionSites, 1, theta_p_threshold, verbose);
try {
bestSSO1 = myMOIP.solve_objective(1, -__DBL_MAX__, __DBL_MAX__);
bestSSO2 = myMOIP.solve_objective(2, -__DBL_MAX__, __DBL_MAX__);
bestSSO1 = myMOIP.solve_objective(1, -__DBL_MAX__, __DBL_MAX__, false);
bestSSO2 = myMOIP.solve_objective(2, -__DBL_MAX__, __DBL_MAX__, false);
bestSSO1.set_pareto_set(1);
bestSSO2.set_pareto_set(1);
myMOIP.add_solution(bestSSO1);
myMOIP.add_solution(bestSSO2);
if (verbose) {
cout << endl << "Best solution according to objective 1 :" << bestSSO1.to_string() << endl;
cout << "Best solution according to objective 2 :" << bestSSO2.to_string() << endl;
......@@ -131,15 +129,17 @@ int main(int argc, char* argv[])
// extend to the whole pareto set
if (MOIP::obj_to_solve_ == 1) {
myMOIP.add_solution(bestSSO1);
if (verbose) cout << endl << "Solving obj1 on top of best solution 1." << endl;
myMOIP.search_between(bestSSO1.get_objective_score(2) + MOIP::epsilon_, bestSSO2.get_objective_score(2));
myMOIP.search_between(bestSSO1.get_objective_score(2) + MOIP::epsilon_, bestSSO2.get_objective_score(2), false);
if (verbose) cout << endl << "Solving obj1 below best solution 1." << endl;
myMOIP.search_between(-__DBL_MAX__, bestSSO1.get_objective_score(2));
myMOIP.search_between(-__DBL_MAX__, bestSSO1.get_objective_score(2), true);
} else {
myMOIP.add_solution(bestSSO2);
if (verbose) cout << endl << "Solving obj2 on top of best solution 2." << endl;
myMOIP.search_between(bestSSO2.get_objective_score(1) + MOIP::epsilon_, bestSSO1.get_objective_score(1));
myMOIP.search_between(bestSSO2.get_objective_score(1) + MOIP::epsilon_, bestSSO1.get_objective_score(1), false);
if (verbose) cout << endl << "Solving obj2 below best solution 2." << endl;
myMOIP.search_between(-__DBL_MAX__, bestSSO2.get_objective_score(1));
myMOIP.search_between(-__DBL_MAX__, bestSSO2.get_objective_score(1), true);
}
} catch (IloAlgorithm::NotExtractedException& e) {
cerr << e << endl;
......