-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of conn criteria (#10)
- Loading branch information
Showing
10 changed files
with
256 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
#MILP Model | ||
cplexpbs.lp | ||
#Opossum files | ||
cplexpb*.lp | ||
cplexpb*.dot | ||
cplexsol.xml | ||
sol-*.dot | ||
|
||
# c++ / cmake | ||
*.o | ||
/bin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
/*******************************************************/ | ||
/* CUDF solver: conn_criteria.h */ | ||
/* Implementation of the conn criteria */ | ||
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */ | ||
/*******************************************************/ | ||
|
||
|
||
#include <conn_criteria.h> | ||
|
||
|
||
// 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 | ||
} | ||
|
||
// Computing the number of columns required to handle the criteria | ||
int conn_criteria::set_variable_range(int first_free_var) { | ||
return first_free_var; | ||
} | ||
|
||
int conn_criteria::rank(pair<FacilityNode*,FacilityNode*> const &path, const unsigned int stage) | ||
{ | ||
return problem->rankZ(path, stage); | ||
} | ||
// 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) { | ||
set_obj_coeff(rank(*p, s), lambda); | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
// 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) { | ||
set_constraint_coeff(rank(*p, s), lambda); | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
int conn_criteria::add_constraints() | ||
{ | ||
return 0; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
/*******************************************************/ | ||
/* CUDF solver: conn_criteria.h */ | ||
/* Concrete class for the conn criteria */ | ||
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */ | ||
/*******************************************************/ | ||
|
||
|
||
#ifndef _CONN_CRITERIA_H_ | ||
#define _CONN_CRITERIA_H_ | ||
|
||
#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. | ||
class conn_criteria: public pslp_criteria{ | ||
public: | ||
|
||
pair<unsigned int, unsigned int> stage_range; | ||
pair<unsigned int, unsigned int> length_range; | ||
|
||
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() {} | ||
|
||
|
||
// 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(); | ||
|
||
int rank(pair<FacilityNode*, FacilityNode*> const &path, const unsigned int stage); | ||
|
||
private : | ||
|
||
inline bool isInRel(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 isInLength(pair<FacilityNode*, FacilityNode*> const & path) { | ||
return isInRange(path.second->getType()->getLevel() - path.first->getType()->getLevel(), length_range); | ||
} | ||
|
||
inline bool isInRL(pair<FacilityNode*, FacilityNode*> const &path) { | ||
return isInRel(path) && isInLength(path); | ||
} | ||
|
||
}; | ||
|
||
#endif | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.