Skip to content

Commit

Permalink
can compile a generic class pslp_criteria (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Jun 14, 2012
1 parent e604b55 commit 3403eac
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 47 deletions.
106 changes: 76 additions & 30 deletions src/abstract_criteria.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,90 @@

// 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() { };
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;

inline bool isInRange(unsigned int val, pair<unsigned int, unsigned int> &range) {
return val >= range.first && val <= range.second;
}

// A generic class for defining PSLP criteria.
class pslp_criteria : public abstract_criteria {
public:
PSLProblem *problem; // a pointer to the problem
abstract_solver *solver; // a pointer to the solver

// select elements according to their reliability (nodes, links, paths ...)
int reliable;
// lambda multiplier for the criteria
CUDFcoefficient lambda_crit ;

// upper bound of the criteria
int _upper_bound;

// Compute the criteria range, upper and lower bounds
virtual CUDFcoefficient bound_range() {
return CUDFabs(lambda_crit) * _upper_bound;
}
virtual CUDFcoefficient upper_bound() {
return _upper_bound;
}
virtual CUDFcoefficient lower_bound() {
return 0;
}

pslp_criteria(CUDFcoefficient lambda_crit, int reliable) : lambda_crit(lambda_crit), reliable(reliable) {};

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

protected :

virtual void set_constraint_coeff(int rank, CUDFcoefficient value) {
solver->set_constraint_coeff(rank, lambda_crit * value);
}

virtual void set_obj_coeff(int rank, CUDFcoefficient value) {
solver->set_obj_coeff(rank, lambda_crit * value + solver->get_obj_coeff(rank));
}
};

#endif

7 changes: 0 additions & 7 deletions src/criteria.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
#include <abstract_solver.h>
#include <abstract_criteria.h>

//#include <removed_criteria.h>
//#include <changed_criteria.h>
//#include <notuptodate_criteria.h>
#include <pserv_criteria.h>
//#include <nunsat_criteria.h>

//#include <count_criteria.h>
//#include <unaligned_criteria.h>

#include <lexagregate_combiner.h>
#include <agregate_combiner.h>
Expand Down
6 changes: 3 additions & 3 deletions src/cudf.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,15 @@ CriteriaList *process_criteria(char *crit_descr, unsigned int &pos, bool first_l
// handle criteria
if (strncmp(crit_descr+crit_name, "pserv", crit_name_length) == 0) {
pair<unsigned int, unsigned int> r1(0, numeric_limits<int>::max()), r2(0,numeric_limits<int>::max() );
int reliable = -1;
int rel = -1;
CUDFcoefficient lambda = 1;
get_criteria_properties(crit_descr, pos,
C_TEXT("type"), r1,
C_TEXT("layer"), r2,
reliable, lambda
rel, lambda
);
if(crit_descr[sign] == '+') {lambda *=-1;}
criteria->push_back(new pserv_criteria(r1, r2, reliable, lambda));
criteria->push_back(new pserv_criteria(lambda, rel, r1, r2));
} else if (strncmp(crit_descr+crit_name, "conn", crit_name_length) == 0) {
//TODO conn_criteria
} else if (strncmp(crit_descr+crit_name, "bandw", crit_name_length) == 0) {
Expand Down
9 changes: 2 additions & 7 deletions src/pserv_criteria.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// not installed in the initial configuration and
// that are installed in the final one.
// The criteria can be restricted to a type of pservers.
class pserv_criteria: public abstract_criteria {
class pserv_criteria: public pslp_criteria{
public:
PSLProblem *problem; // a pointer to the problem
abstract_solver *solver; // a pointer to the solver
Expand All @@ -26,7 +26,6 @@ class pserv_criteria: public abstract_criteria {

// Allocate some columns for the criteria
int set_variable_range(int first_free_var);

// Add the criteria to the objective
int add_criteria_to_objective(CUDFcoefficient lambda);
// Add the criteria to the constraint set
Expand All @@ -52,17 +51,13 @@ class pserv_criteria: public abstract_criteria {
// lambda multiplier for the criteria
CUDFcoefficient lambda_crit ;

pserv_criteria(pair<unsigned int, unsigned int> pserv_range, pair<unsigned int, unsigned int> layer_range, int reliable, CUDFcoefficient lambda_crit) : pserv_range(pserv_range), layer_range(layer_range), reliable(reliable), lambda_crit(lambda_crit) {};
pserv_criteria(CUDFcoefficient lambda_crit, int reliable, pair<unsigned int, unsigned int> pserv_range, pair<unsigned int, unsigned int> layer_range) : pslp_criteria(lambda_crit, reliable), pserv_range(pserv_range), layer_range(layer_range) {};

private :
inline bool all_pserv() {
return pserv_range.first <= 0 && problem->serverTypeCount() -1 <= pserv_range.second;
}

bool isInRange(unsigned int val, pair<unsigned int, unsigned int> &range) {
return val >= range.first && val <= range.second;
}

inline bool isInRel(FacilityNode* node) {
if(reliable < 0) return true;
else {
Expand Down

0 comments on commit 3403eac

Please sign in to comment.