1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*******************************************************/
/* CUDF solver: notuptodate_criteria.c */
/* Implementation the notuptodate criteria */
/* (c) Claude Michel I3S (UNSA-CNRS) 2009,2010,2011 */
/*******************************************************/
#include <notuptodate_criteria.h>
// Implementation of the not up to date criteria
//
// Criteria initialization
void notuptodate_criteria::initialize(CUDFproblem *problem, abstract_solver *solver) {
this->problem = problem;
this->solver = solver;
ub = 0;
for (CUDFVirtualPackageListIterator ivpkg = problem->all_virtual_packages->begin();
ivpkg != problem->all_virtual_packages->end(); ivpkg++)
if ((*ivpkg)->all_versions.size() > 1) ub++;
}
// Computing the number of columns required to handle the criteria
int notuptodate_criteria::set_variable_range(int first_free_var) {
this->first_free_var = first_free_var;
return first_free_var + ub;
}
// Add the criteria to the current objective function
int notuptodate_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {
int ivpkg_rank = first_free_var;
for (CUDFVirtualPackageListIterator ivpkg = problem->all_virtual_packages->begin();
ivpkg != problem->all_virtual_packages->end(); ivpkg++)
if ((*ivpkg)->all_versions.size() > 1) solver->set_obj_coeff(ivpkg_rank++, lambda_crit * lambda);
return 0;
}
// Add the criteria to the constraint set
int notuptodate_criteria::add_criteria_to_constraint(CUDFcoefficient lambda) {
int ivpkg_rank = first_free_var;
for (CUDFVirtualPackageListIterator ivpkg = problem->all_virtual_packages->begin();
ivpkg != problem->all_virtual_packages->end(); ivpkg++)
if ((*ivpkg)->all_versions.size() > 1) solver->set_constraint_coeff(ivpkg_rank++, lambda_crit * lambda);
return 0;
}
// Add the constraints required by the criteria
int notuptodate_criteria::add_constraints() {
int ivpkg_rank = first_free_var;
for (CUDFVirtualPackageListIterator ivpkg = problem->all_virtual_packages->begin();
ivpkg != problem->all_virtual_packages->end(); ivpkg++) {
int size = (*ivpkg)->all_versions.size();
if (size > 1) {
solver->new_constraint();
for (CUDFVersionedPackageSetIterator vers_pkg = (*ivpkg)->all_versions.begin(); vers_pkg != (*ivpkg)->all_versions.end(); vers_pkg++)
if ((*vers_pkg)->version == (*ivpkg)->highest_version)
solver->set_constraint_coeff((*vers_pkg)->rank, -(size - 1));
else
solver->set_constraint_coeff((*vers_pkg)->rank, +1);
solver->set_constraint_coeff(ivpkg_rank, -size);
solver->add_constraint_leq(+0);
solver->new_constraint();
for (CUDFVersionedPackageSetIterator vers_pkg = (*ivpkg)->all_versions.begin(); vers_pkg != (*ivpkg)->all_versions.end(); vers_pkg++)
if ((*vers_pkg)->version == (*ivpkg)->highest_version)
solver->set_constraint_coeff((*vers_pkg)->rank, -(size - 1));
else
solver->set_constraint_coeff((*vers_pkg)->rank, +1);
solver->set_constraint_coeff(ivpkg_rank, -size);
solver->add_constraint_geq(-size+1);
ivpkg_rank++;
}
}
return 0;
}
// Compute the criteria range
CUDFcoefficient notuptodate_criteria::bound_range() { return CUDFabs(lambda_crit) * ub; }
// Compute the criteria upper bound
CUDFcoefficient notuptodate_criteria::upper_bound() {
if (lambda_crit >= 0)
return lambda_crit * ub;
else
return 0;
}
// Compute the criteria lower bound
CUDFcoefficient notuptodate_criteria::lower_bound() {
if (lambda_crit >= 0)
return 0;
else
return lambda_crit * ub;
}
|