Skip to content

Commit

Permalink
improve criteria hierarchy (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-m committed Jun 18, 2012
1 parent 3e93884 commit bf2d839
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 252 deletions.
58 changes: 7 additions & 51 deletions src/bandw_criteria.c
Original file line number Diff line number Diff line change
@@ -1,68 +1,24 @@

/*******************************************************/
/* CUDF solver: bandw_criteria.c */
/* CUDF solver: bandw_criteria.h */
/* Implementation of the bandw criteria */
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
/*******************************************************/


#include <bandw_criteria.h>


// Criteria initialization
void bandw_criteria::initialize(PSLProblem *problem, abstract_solver *solver) {
pslp_criteria::initialize(problem, solver);
stage_range.set_min_limit(0);
stage_range.set_max_limit(problem->stageCount() - 1);
length_range.set_min_limit(1); //No bandwidth variables for local connections
//TODO Initialize upper bound
}

// Computing the number of columns required to handle the criteria
int bandw_criteria::set_variable_range(int first_free_var) {
return first_free_var;
}

int bandw_criteria::rank(pair<FacilityNode*,FacilityNode*> const &path, const unsigned int stage)
void bandw_criteria::initialize_upper_bound(PSLProblem *problem)
{
return problem->rankB(path, stage);
}

// Add the criteria to the current objective function
int bandw_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
if(isRLSelected(*p)) {
for (int s = stage_range.min(); s <= stage_range.max(); ++s) {
set_obj_coeff(rank(*p, s), lambda);
}
}
_upper_bound = 0;
for(LinkIterator i = problem->lbegin() ; i!= problem->lend() ; i++) {
_upper_bound += i->getBandwidth();
}
return 0;
}

// Add the criteria to the constraint set
int bandw_criteria::add_criteria_to_constraint(CUDFcoefficient lambda) {

for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
if(isRLSelected(*p)) {
for (int s = stage_range.min(); s <= stage_range.max(); ++s) {
set_constraint_coeff(rank(*p, s), lambda);
}
}
}
return 0;
}

int bandw_criteria::add_constraints()
int bandw_criteria::rank(const pair<FacilityNode*,FacilityNode*> & path, const unsigned int stage)
{
return 0;
return problem->rankB(path, stage);
}









37 changes: 5 additions & 32 deletions src/bandw_criteria.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

/*******************************************************/
/* CUDF solver: bandw_criteria.h */
/* CUDF solver: bandw_criteria.h */
/* Concrete class for the bandw criteria */
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
/*******************************************************/
Expand All @@ -9,45 +8,19 @@
#ifndef _BANDW_CRITERIA_H_
#define _BANDW_CRITERIA_H_

#include <abstract_criteria.h>
#include <conn_criteria.h>

// A concrete class for the bandw criteria
// i.e. the bandwidth allocated to connections.
class bandw_criteria: public pslp_criteria{
class bandw_criteria: public conn_criteria{
public:

param_range stage_range;
param_range length_range;

bandw_criteria(CUDFcoefficient lambda_crit, int reliable, param_range stage_range, param_range length_range) : pslp_criteria(lambda_crit, reliable), stage_range(stage_range), length_range(length_range) {};
bandw_criteria(CUDFcoefficient lambda_crit, int reliable, param_range stage_range, param_range length_range) : conn_criteria(lambda_crit, reliable, stage_range, length_range) {};
virtual ~bandw_criteria() {}


// Criteria initialization
void initialize(PSLProblem *problem, abstract_solver *solver);

// 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
int add_criteria_to_constraint(CUDFcoefficient lambda);
// Add constraints required by the criteria
int add_constraints();

void initialize_upper_bound(PSLProblem *problem);
int rank(pair<FacilityNode*, FacilityNode*> const &path, const unsigned int stage);

private :

inline bool isRLSelected(pair<FacilityNode*, FacilityNode*> const &path) {
if(length_range.contains(path.second->getType()->getLevel() - path.first->getType()->getLevel())) {
return reliable == 0 ? ! isReliablePath(path.first, path.second) :
reliable > 0 ? isReliablePath(path.first, path.second) : true;
}
return false;

}

};

#endif
Expand Down
53 changes: 24 additions & 29 deletions src/conn_criteria.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/*******************************************************/
/* CUDF solver: conn_criteria.h */
/* Implementation of the conn criteria */
/* CUDF solver: conn_criteria.c */
/* Implementation of the conn criteria */
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
/*******************************************************/

Expand All @@ -12,34 +12,38 @@
// Criteria initialization
void conn_criteria::initialize(PSLProblem *problem, abstract_solver *solver) {
pslp_criteria::initialize(problem, solver);
stage_max = min(stage_range.second, problem->stageCount() - 1);
//TODO Initialize upper bound
stage_range.set_min_limit(0);
stage_range.set_max_limit(problem->stageCount() - 1);
length_range.set_min_limit(1); //Ignore local connections
initialize_upper_bound(problem);
}

// Computing the number of columns required to handle the criteria
int conn_criteria::set_variable_range(int first_free_var) {
return first_free_var;
// Criteria initialization
void conn_criteria::initialize_upper_bound(PSLProblem *problem) {
_upper_bound = 0;
for(NodeIterator i = problem->nbegin() ; i!= problem->nend() ; i++) {
_upper_bound += i->getType()->getTotalDemand();
}
}


int conn_criteria::rank(pair<FacilityNode*,FacilityNode*> const &path, const unsigned int stage)
{
return problem->rankZ(path, stage);
}

// Computing the number of columns required to handle the criteria
int conn_criteria::set_variable_range(int first_free_var) {
return first_free_var;
}



// Add the criteria to the current objective function
int conn_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {
if(isInRange(0, length_range)) {
for (NodeIterator n = problem->getRoot()->nbegin(); n != problem->getRoot()->nend(); ++n) {
if(reliable != 0) { //local connections are reliable.
for (int s = stage_range.first; s <= stage_max; ++s) {
set_obj_coeff(problem->rankZ(*n, s), lambda);
}
}
}
}
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
if(isInRL(*p)) {
for (int s = stage_range.first; s <= stage_max; ++s) {
if(isRLSelected(*p)) {
for (int s = stage_range.min(); s <= stage_range.max(); ++s) {
set_obj_coeff(rank(*p, s), lambda);
}
}
Expand All @@ -49,18 +53,9 @@ int conn_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {

// Add the criteria to the constraint set
int conn_criteria::add_criteria_to_constraint(CUDFcoefficient lambda) {
if(isInRange(0, length_range)) {
for (NodeIterator n = problem->getRoot()->nbegin(); n != problem->getRoot()->nend(); ++n) {
if(reliable != 0) { //local connections are reliable.
for (int s = stage_range.first; s <= stage_max; ++s) {
set_constraint_coeff(problem->rankZ(*n, s), lambda);
}
}
}
}
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
if(isInRL(*p)) {
for (int s = stage_range.first; s <= stage_max; ++s) {
if(isRLSelected(*p)) {
for (int s = stage_range.min(); s <= stage_range.max(); ++s) {
set_constraint_coeff(rank(*p, s), lambda);
}
}
Expand Down
38 changes: 15 additions & 23 deletions src/conn_criteria.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/*******************************************************/
/* CUDF solver: conn_criteria.h */
/* Concrete class for the conn criteria */
/* CUDF solver: bandw_criteria.h */
/* Concrete class for the bandw criteria */
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
/*******************************************************/

Expand All @@ -12,18 +12,16 @@
#include <abstract_criteria.h>

// A concrete class for the conn criteria
// i.e. the number of connections between a pserver and a client.
// the scope of connections can be retricted by using properties.
// i.e. the number of connections.
class conn_criteria: public pslp_criteria{
public:

pair<unsigned int, unsigned int> stage_range;
pair<unsigned int, unsigned int> length_range;
param_range stage_range;
param_range length_range;
CUDFcoefficient local_lambda;

unsigned int stage_max;

conn_criteria(CUDFcoefficient lambda_crit, int reliable, pair<unsigned int, unsigned int> stage_range, pair<unsigned int, unsigned int> length_range) : pslp_criteria(lambda_crit, reliable), stage_range(stage_range), length_range(length_range) {};
virtual ~conn_criteria() {}
conn_criteria(CUDFcoefficient lambda_crit, int reliable, param_range stage_range, param_range length_range) : pslp_criteria(lambda_crit, reliable), stage_range(stage_range), length_range(length_range) {};
virtual ~conn_criteria() {}


// Criteria initialization
Expand All @@ -38,24 +36,18 @@ class conn_criteria: public pslp_criteria{
// Add constraints required by the criteria
int add_constraints();

int rank(pair<FacilityNode*, FacilityNode*> const &path, const unsigned int stage);
virtual void initialize_upper_bound(PSLProblem *problem);
virtual int rank(pair<FacilityNode*, FacilityNode*> const &path, const unsigned int stage);

private :

inline bool isReliable(pair<FacilityNode*, FacilityNode*> const & path) {
if(reliable < 0) return true;
else {
const bool relp = isReliablePath(path.first, path.second);
return reliable == 0 ? !relp : relp;
inline bool isRLSelected(pair<FacilityNode*, FacilityNode*> const &path) {
if(length_range.contains(path.second->getType()->getLevel() - path.first->getType()->getLevel())) {
return reliable == 0 ? ! isReliablePath(path.first, path.second) :
reliable > 0 ? isReliablePath(path.first, path.second) : true;
}
}

inline bool isInLength(pair<FacilityNode*, FacilityNode*> const & path) {
return isInRange(path.second->getType()->getLevel() - path.first->getType()->getLevel(), length_range);
}
return false;

inline bool isInRL(pair<FacilityNode*, FacilityNode*> const &path) {
return isReliable(path) && isInLength(path);
}

};
Expand Down
21 changes: 12 additions & 9 deletions src/constraint_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

int new_var = 0;
CUDFcoefficient min_bandwidth = 1; //set min_bandwidth to 1Ko
CUDFcoefficient max_bandwidth = 5000; //set min_bandwidth to 1Ko

struct SetPathCoeff {

Expand Down Expand Up @@ -114,15 +115,15 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_

///////////
//the number of provided connections is the sum of the numbers of local and outgoing connections.
// for (int s = 0; s < problem->stageCount(); ++s) {
// solver.new_constraint();
// solver.set_constraint_coeff(problem->rankY(*i, s),1);
// solver.set_constraint_coeff(problem->rankZ(*i, s), -1);
// for(NodeIterator p = i->nbegin() ; p!= i->nend() ; p++) {
// solver.set_constraint_coeff( problem->rankZ(*i, *p, s), 1);
// }
// solver.add_constraint_eq(i->getType()->getDemand(s));
// }
// for (int s = 0; s < problem->stageCount(); ++s) {
// solver.new_constraint();
// solver.set_constraint_coeff(problem->rankY(*i, s),1);
// solver.set_constraint_coeff(problem->rankZ(*i, s), -1);
// for(NodeIterator p = i->nbegin() ; p!= i->nend() ; p++) {
// solver.set_constraint_coeff( problem->rankZ(*i, *p, s), 1);
// }
// solver.add_constraint_eq(i->getType()->getDemand(s));
// }



Expand Down Expand Up @@ -213,6 +214,8 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
solver.set_constraint_coeff(problem->rankB(*i, *j, s), 1);
solver.set_constraint_coeff(problem->rankZ(*i, *j, s), - min_bandwidth);
solver.add_constraint_geq(0);
///////////
//TODO maximal bandwidth for a single connection
}
j++;
}
Expand Down
26 changes: 13 additions & 13 deletions src/constraint_generation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@

extern int new_var;
extern CUDFcoefficient min_bandwidth;

extern CUDFcoefficient max_bandwidth;

// available criteria
#define CRIT_DEFAULT 1
#define CRIT_CONSERVATIVE 2
#define CRIT_FRESHER 3
#define CRIT_SFRESHER 4
#define CRIT_FFRESHER 5
#define CRIT_TFRESHER 5
#define CRIT_PARANOID 6
#define CRIT_TRENDY 7
#define CRIT_TRENDY2 8
#define CRIT_LEXPARANOID 9
#define CRIT_LEXTRENDY 10
#define CRIT_LEXTRENDY2 11
//#define CRIT_DEFAULT 1
//#define CRIT_CONSERVATIVE 2
//#define CRIT_FRESHER 3
//#define CRIT_SFRESHER 4
//#define CRIT_FFRESHER 5
//#define CRIT_TFRESHER 5
//#define CRIT_PARANOID 6
//#define CRIT_TRENDY 7
//#define CRIT_TRENDY2 8
//#define CRIT_LEXPARANOID 9
//#define CRIT_LEXTRENDY 10
//#define CRIT_LEXTRENDY2 11


// main function for constraint generation (translate a CUDF problem into MILP problem for a given solver and a given criteria)
Expand Down
Loading

0 comments on commit bf2d839

Please sign in to comment.