Skip to content

Commit

Permalink
First commit of some mccs code (#4, start #9, init #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Feb 21, 2012
1 parent c4d8920 commit fe0b930
Show file tree
Hide file tree
Showing 40 changed files with 4,891 additions and 172 deletions.
19 changes: 0 additions & 19 deletions include/.gitignore

This file was deleted.

36 changes: 36 additions & 0 deletions src/abstract_combiner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

/*******************************************************/
/* CUDF solver: abstract_combiner.h */
/* Abstract class for combiners */
/* (c) Claude Michel I3S (UNSA-CNRS) 2009,2010,2011 */
/*******************************************************/


#ifndef __ABSTRACT_COMBINER_H
#define __ABSTRACT_COMBINER_H

#include <abstract_criteria.h>

// An anstract combiner
class abstract_combiner {
public:
// Called to know the number of columns required by the combiner
virtual int column_allocation(int first_rank) { return first_rank; }

// Method in charge of the combiner objective generation
virtual int objective_generation() { return 0; }

// Method in charge of the combiner constraint generation
virtual int constraint_generation() { return 0; }

// Tells whether this combiner allows problem reductions or not
virtual bool can_reduce() { return true; }

// Called to let the combiner initializes itself
virtual void initialize(PSLProblem *problem, abstract_solver *solver) { };

// Combiner destructor
virtual ~abstract_combiner() { };
};

#endif
57 changes: 57 additions & 0 deletions src/abstract_criteria.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

/*******************************************************/
/* CUDF solver: abstract_criteria.h */
/* Abstract class for criteria */
/* (c) Claude Michel I3S (UNSA-CNRS) 2009,2010,2011 */
/*******************************************************/



#ifndef _ABSTRACT_CRITERIA_H_
#define _ABSTRACT_CRITERIA_H_

#include <abstract_solver.h>

// Abstract criteria class
class abstract_criteria {
public:
// Method called to allocate some variables (columns) to the criteria
virtual int set_variable_range(int first_free_var) { return 0; }
// Method called to add the criteria to the current objective
virtual int add_criteria_to_objective(CUDFcoefficient lambda) { return 0; };
// Method called to add the criteria to the constraints
virtual int add_criteria_to_constraint(CUDFcoefficient lambda) { return 0; };
// Method called to add criteria related constraints
virtual int add_constraints() { return 0; };

// Gives the range of the criteria objective
virtual CUDFcoefficient bound_range() { return 0; };
// Gives the upper bound of the criteria objective
virtual CUDFcoefficient upper_bound() { return 0; };
// Gives the lower bound of the criteria objective
virtual CUDFcoefficient lower_bound() { return 0; };

// Does this criteria allows problem reduction ?
virtual bool can_reduce(CUDFcoefficient lambda) { return true; }

// Method called to let the criteria initializes itself
virtual void initialize(PSLProblem *problem, abstract_solver *solver) { };
// Method called to initialize criteria variables
virtual void initialize_intvars() { };

//Method called to let the criteria checks some properties availability
virtual void check_property(PSLProblem *problem) {};

// Criteria destructor
virtual ~abstract_criteria() { };
};

// Type for a list of criteria
typedef vector<abstract_criteria *> CriteriaList;
typedef CriteriaList::iterator CriteriaListIterator;

// Shall we optimize variable usage or not
extern bool criteria_opt_var;

#endif

111 changes: 111 additions & 0 deletions src/abstract_solver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@

/*******************************************************/
/* CUDF solver: abstract_solver.h */
/* Abstract class for solvers */
/* (c) Claude Michel I3S (UNSA-CNRS) 2009,2010,2011 */
/*******************************************************/

// Solver abstraction
// all implemented solvers are implemented through a concrete class that inherits and implements an abstract solver.

#ifndef _ABSTRACT_SOLVER_H
#define _ABSTRACT_SOLVER_H

#include <cudf.h>
//#include <cudf_types.h>


// provide an abstraction of the underlying solvers
class abstract_solver {
public:
// ******************************************************************
// solver initialisation method (called at the beginning of constraint generation)
virtual int init_solver(PSLProblem *problem, int other_vars) { return 0; };

// ******************************************************************
// does the solver has the capability to handle integer variables
virtual bool has_intvars() { return false; };

// set variable type to int and its range to [lower, upper] (must be used before end_objectives)
virtual int set_intvar_range(int rank, CUDFcoefficient lower, CUDFcoefficient upper) { return 0; }

// ******************************************************************
// called before objective definitions
virtual int begin_objectives(void) { return 0; };

// get the current coefficient value of the objective function for parameter package
//FIXME virtual CUDFcoefficient get_obj_coeff(CUDFVersionedPackage *package) { return 0; };
// get the current coefficient value of the objective function for variable rank
virtual CUDFcoefficient get_obj_coeff(int rank) { return 0; };

// set objective coefficient value according to a package
//FIXME virtual int set_obj_coeff(CUDFVersionedPackage *package, CUDFcoefficient value) { return 0; };
// set objective coefficient value according to a rank (column number)
virtual int set_obj_coeff(int rank, CUDFcoefficient value) { return 0; };

// called before defining a new objective
virtual int new_objective(void) { return 0; };

// called to add a new objective
virtual int add_objective(void) { return 0; };

// called at the end of objective definitions
virtual int end_objectives(void) { return 0; };

// ******************************************************************
// constraint generation

// called before the definition of any constraint
virtual int begin_add_constraints(void) { return 0; };

// called before the definition of a new constraint
virtual int new_constraint(void) { return 0; };

// get current constraint coefficient according to a package
//FIXME virtual CUDFcoefficient get_constraint_coeff(CUDFVersionedPackage *package) { return 0; };
// get current constraint coefficient according to a rank
virtual CUDFcoefficient get_constraint_coeff(int rank) { return 0; };

// set constraint coefficient of a package
//FIXME virtual int set_constraint_coeff(CUDFVersionedPackage *package, CUDFcoefficient value) { return 0; };
// set constraint coefficient of a rank (i.e. column number)
virtual int set_constraint_coeff(int rank, CUDFcoefficient value) { return 0; };

// define the constraint as greater or equal to a bound (called once all constraints coefficients have been defined)
virtual int add_constraint_geq(CUDFcoefficient bound) { return 0; };
// define the constraint as less or equal to a bound (called once all constraints coefficients have been defined)
virtual int add_constraint_leq(CUDFcoefficient bound) { return 0; };
// define the constraint as equal to a bound (called once all constraints coefficients have been defined)
virtual int add_constraint_eq(CUDFcoefficient bound) { return 0; };

// called once all constraints have been defined
virtual int end_add_constraints(void) { return 0; };


// ******************************************************************
// write the internal representation of the problem to a file
virtual int writelp(char *filename) { return 0; };

// ******************************************************************
// solve the problem (must return a value > 0 if a solution has been found)
virtual int solve() { return 0; };

// ******************************************************************
// initialisation of the solutions (called before reading them)
virtual int init_solutions() { return 0; };

// get the objective value at the end of solving
virtual CUDFcoefficient objective_value() { return 0; };

// get the status of a package in the final configuration
//FIXME virtual CUDFcoefficient get_solution(CUDFVersionedPackage *package) { return 0; };
virtual CUDFcoefficient get_solution(int k) { return 0; };

// ******************************************************************
// abstract solver destructor
virtual ~abstract_solver() {};

};


#endif
124 changes: 124 additions & 0 deletions src/agregate_combiner.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

/*******************************************************/
/* CUDF solver: agregate_combiner.c */
/* Implementation of the agregate combiner */
/* (c) Claude Michel I3S (UNSA-CNRS) 2009,2010,2011 */
/*******************************************************/


#include <stdio.h>
#include <agregate_combiner.h>

// Compute the number of columns required to handle the agregate
int agregate_combiner::column_allocation(int first_rank) {
for (CriteriaListIterator crit = criteria->begin(); crit != criteria->end(); crit++)
first_rank = (*crit)->set_variable_range(first_rank);
return first_rank;
}

// Generate the objective function
int agregate_combiner::objective_generation() {
// Allow criteria to set the range of their integer variables
for (CriteriaListIterator icrit = criteria->begin(); icrit != criteria->end(); icrit++) (*icrit)->initialize_intvars();

solver->new_objective();
add_criteria_to_objective(1);
solver->add_objective();
return 0;
}

// Ask to criteria to generate their own constraints
int agregate_combiner::constraint_generation() {
for (CriteriaListIterator crit = criteria->begin(); crit != criteria->end(); crit++)
(*crit)->add_constraints();
return 0;
}

// Combiner initialization
void agregate_combiner::initialize(PSLProblem *problem, abstract_solver *solver) {
this->solver = solver;
for (CriteriaListIterator crit = criteria->begin(); crit != criteria->end(); crit++) (*crit)->initialize(problem, solver);
}

// Compute the number of required columns when the combiner is used as a criteria
int agregate_combiner::set_variable_range(int first_free_var) {
for (CriteriaListIterator crit = criteria->begin(); crit != criteria->end(); crit++)
first_free_var = (*crit)->set_variable_range(first_free_var);

return first_free_var;
}

// Add the combiner as a criteria to the curent objective function
int agregate_combiner::add_criteria_to_objective(CUDFcoefficient lambda) {
for (CriteriaList::iterator crit = criteria->begin(); crit != criteria->end(); ++crit)
(*crit)->add_criteria_to_objective(lambda_crit*lambda);
return 0;
}

// Add the combiner objective as a constraint
int agregate_combiner::add_criteria_to_constraint(CUDFcoefficient lambda) {
for (CriteriaList::iterator crit = criteria->begin(); crit != criteria->end(); ++crit)
(*crit)->add_criteria_to_constraint(lambda_crit*lambda);
return 0;
}

// Add the required constraints (from the criteria set)
int agregate_combiner::add_constraints() { return constraint_generation(); }

// Compute the range of the combiner/criteria
CUDFcoefficient agregate_combiner::bound_range() {
CUDFcoefficient range = 0;

for (CriteriaList::reverse_iterator crit = criteria->rbegin(); crit != criteria->rend(); ++crit)
range += CUDFabs(lambda_crit) * (*crit)->bound_range();
return range;
}

// Compute the upper bound of the combiner/criteria
CUDFcoefficient agregate_combiner::upper_bound() {
CUDFcoefficient ub = 0;

for (CriteriaList::reverse_iterator crit = criteria->rbegin(); crit != criteria->rend(); ++crit)
if (lambda_crit >= 0)
ub += lambda_crit * (*crit)->upper_bound();
else
ub += lambda_crit * (*crit)->lower_bound();
return ub;
}

// Compute the lower bound of the combiner/criteria
CUDFcoefficient agregate_combiner::lower_bound() {
CUDFcoefficient lb = 0;

for (CriteriaList::reverse_iterator crit = criteria->rbegin(); crit != criteria->rend(); ++crit)
if (lambda_crit >= 0)
lb += lambda_crit * (*crit)->lower_bound();
else
lb += lambda_crit * (*crit)->upper_bound();
return lb;
}

// Does the combiner/criteria allows problem reduction
bool agregate_combiner::can_reduce() {
bool result = true;

for (CriteriaListIterator crit = criteria->begin(); crit != criteria->end(); crit++)
result = result && (*crit)->can_reduce(lambda_crit);
return result;
}

// Does the combiner/criteria allows problem reduction (taking into account lambda multiplier)
bool agregate_combiner::can_reduce(CUDFcoefficient lambda) {
bool result = true;
CUDFcoefficient l = lambda * lambda_crit;

for (CriteriaListIterator crit = criteria->begin(); crit != criteria->end(); crit++)
result = result && (*crit)->can_reduce(l);
return result;
}

// Initialize integer variables (from criteria set)
void agregate_combiner::initialize_intvars() {
for (CriteriaListIterator crit = criteria->begin(); crit != criteria->end(); crit++)
(*crit)->initialize_intvars();
}
Loading

0 comments on commit fe0b930

Please sign in to comment.