Skip to content

Commit bf2d839

Browse files
committed
improve criteria hierarchy (#10)
1 parent 3e93884 commit bf2d839

9 files changed

+102
-252
lines changed

src/bandw_criteria.c

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,24 @@
1-
21
/*******************************************************/
3-
/* CUDF solver: bandw_criteria.c */
2+
/* CUDF solver: bandw_criteria.h */
43
/* Implementation of the bandw criteria */
54
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
65
/*******************************************************/
76

8-
97
#include <bandw_criteria.h>
108

119

12-
// Criteria initialization
13-
void bandw_criteria::initialize(PSLProblem *problem, abstract_solver *solver) {
14-
pslp_criteria::initialize(problem, solver);
15-
stage_range.set_min_limit(0);
16-
stage_range.set_max_limit(problem->stageCount() - 1);
17-
length_range.set_min_limit(1); //No bandwidth variables for local connections
18-
//TODO Initialize upper bound
19-
}
20-
21-
// Computing the number of columns required to handle the criteria
22-
int bandw_criteria::set_variable_range(int first_free_var) {
23-
return first_free_var;
24-
}
25-
26-
int bandw_criteria::rank(pair<FacilityNode*,FacilityNode*> const &path, const unsigned int stage)
10+
void bandw_criteria::initialize_upper_bound(PSLProblem *problem)
2711
{
28-
return problem->rankB(path, stage);
29-
}
30-
31-
// Add the criteria to the current objective function
32-
int bandw_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {
33-
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
34-
if(isRLSelected(*p)) {
35-
for (int s = stage_range.min(); s <= stage_range.max(); ++s) {
36-
set_obj_coeff(rank(*p, s), lambda);
37-
}
38-
}
12+
_upper_bound = 0;
13+
for(LinkIterator i = problem->lbegin() ; i!= problem->lend() ; i++) {
14+
_upper_bound += i->getBandwidth();
3915
}
40-
return 0;
4116
}
4217

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

46-
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
47-
if(isRLSelected(*p)) {
48-
for (int s = stage_range.min(); s <= stage_range.max(); ++s) {
49-
set_constraint_coeff(rank(*p, s), lambda);
50-
}
51-
}
52-
}
53-
return 0;
54-
}
5519

56-
int bandw_criteria::add_constraints()
20+
int bandw_criteria::rank(const pair<FacilityNode*,FacilityNode*> & path, const unsigned int stage)
5721
{
58-
return 0;
22+
return problem->rankB(path, stage);
5923
}
6024

61-
62-
63-
64-
65-
66-
67-
68-

src/bandw_criteria.h

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
/*******************************************************/
3-
/* CUDF solver: bandw_criteria.h */
2+
/* CUDF solver: bandw_criteria.h */
43
/* Concrete class for the bandw criteria */
54
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
65
/*******************************************************/
@@ -9,45 +8,19 @@
98
#ifndef _BANDW_CRITERIA_H_
109
#define _BANDW_CRITERIA_H_
1110

12-
#include <abstract_criteria.h>
11+
#include <conn_criteria.h>
1312

1413
// A concrete class for the bandw criteria
1514
// i.e. the bandwidth allocated to connections.
16-
class bandw_criteria: public pslp_criteria{
15+
class bandw_criteria: public conn_criteria{
1716
public:
1817

19-
param_range stage_range;
20-
param_range length_range;
21-
22-
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) {};
18+
bandw_criteria(CUDFcoefficient lambda_crit, int reliable, param_range stage_range, param_range length_range) : conn_criteria(lambda_crit, reliable, stage_range, length_range) {};
2319
virtual ~bandw_criteria() {}
2420

25-
26-
// Criteria initialization
27-
void initialize(PSLProblem *problem, abstract_solver *solver);
28-
29-
// Allocate some columns for the criteria
30-
int set_variable_range(int first_free_var);
31-
// Add the criteria to the objective
32-
int add_criteria_to_objective(CUDFcoefficient lambda);
33-
// Add the criteria to the constraint set
34-
int add_criteria_to_constraint(CUDFcoefficient lambda);
35-
// Add constraints required by the criteria
36-
int add_constraints();
37-
21+
void initialize_upper_bound(PSLProblem *problem);
3822
int rank(pair<FacilityNode*, FacilityNode*> const &path, const unsigned int stage);
3923

40-
private :
41-
42-
inline bool isRLSelected(pair<FacilityNode*, FacilityNode*> const &path) {
43-
if(length_range.contains(path.second->getType()->getLevel() - path.first->getType()->getLevel())) {
44-
return reliable == 0 ? ! isReliablePath(path.first, path.second) :
45-
reliable > 0 ? isReliablePath(path.first, path.second) : true;
46-
}
47-
return false;
48-
49-
}
50-
5124
};
5225

5326
#endif

src/conn_criteria.c

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*******************************************************/
3-
/* CUDF solver: conn_criteria.h */
4-
/* Implementation of the conn criteria */
3+
/* CUDF solver: conn_criteria.c */
4+
/* Implementation of the conn criteria */
55
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
66
/*******************************************************/
77

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

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

29+
2430
int conn_criteria::rank(pair<FacilityNode*,FacilityNode*> const &path, const unsigned int stage)
2531
{
2632
return problem->rankZ(path, stage);
2733
}
2834

35+
// Computing the number of columns required to handle the criteria
36+
int conn_criteria::set_variable_range(int first_free_var) {
37+
return first_free_var;
38+
}
39+
40+
41+
2942
// Add the criteria to the current objective function
3043
int conn_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {
31-
if(isInRange(0, length_range)) {
32-
for (NodeIterator n = problem->getRoot()->nbegin(); n != problem->getRoot()->nend(); ++n) {
33-
if(reliable != 0) { //local connections are reliable.
34-
for (int s = stage_range.first; s <= stage_max; ++s) {
35-
set_obj_coeff(problem->rankZ(*n, s), lambda);
36-
}
37-
}
38-
}
39-
}
4044
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
41-
if(isInRL(*p)) {
42-
for (int s = stage_range.first; s <= stage_max; ++s) {
45+
if(isRLSelected(*p)) {
46+
for (int s = stage_range.min(); s <= stage_range.max(); ++s) {
4347
set_obj_coeff(rank(*p, s), lambda);
4448
}
4549
}
@@ -49,18 +53,9 @@ int conn_criteria::add_criteria_to_objective(CUDFcoefficient lambda) {
4953

5054
// Add the criteria to the constraint set
5155
int conn_criteria::add_criteria_to_constraint(CUDFcoefficient lambda) {
52-
if(isInRange(0, length_range)) {
53-
for (NodeIterator n = problem->getRoot()->nbegin(); n != problem->getRoot()->nend(); ++n) {
54-
if(reliable != 0) { //local connections are reliable.
55-
for (int s = stage_range.first; s <= stage_max; ++s) {
56-
set_constraint_coeff(problem->rankZ(*n, s), lambda);
57-
}
58-
}
59-
}
60-
}
6156
for (PathIterator p = problem->getRoot()->pbegin(); p != problem->getRoot()->pend(); ++p) {
62-
if(isInRL(*p)) {
63-
for (int s = stage_range.first; s <= stage_max; ++s) {
57+
if(isRLSelected(*p)) {
58+
for (int s = stage_range.min(); s <= stage_range.max(); ++s) {
6459
set_constraint_coeff(rank(*p, s), lambda);
6560
}
6661
}

src/conn_criteria.h

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*******************************************************/
3-
/* CUDF solver: conn_criteria.h */
4-
/* Concrete class for the conn criteria */
3+
/* CUDF solver: bandw_criteria.h */
4+
/* Concrete class for the bandw criteria */
55
/* (c) Arnaud Malapert I3S (UNSA-CNRS) 2012 */
66
/*******************************************************/
77

@@ -12,18 +12,16 @@
1212
#include <abstract_criteria.h>
1313

1414
// A concrete class for the conn criteria
15-
// i.e. the number of connections between a pserver and a client.
16-
// the scope of connections can be retricted by using properties.
15+
// i.e. the number of connections.
1716
class conn_criteria: public pslp_criteria{
1817
public:
1918

20-
pair<unsigned int, unsigned int> stage_range;
21-
pair<unsigned int, unsigned int> length_range;
19+
param_range stage_range;
20+
param_range length_range;
21+
CUDFcoefficient local_lambda;
2222

23-
unsigned int stage_max;
24-
25-
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) {};
26-
virtual ~conn_criteria() {}
23+
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) {};
24+
virtual ~conn_criteria() {}
2725

2826

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

41-
int rank(pair<FacilityNode*, FacilityNode*> const &path, const unsigned int stage);
39+
virtual void initialize_upper_bound(PSLProblem *problem);
40+
virtual int rank(pair<FacilityNode*, FacilityNode*> const &path, const unsigned int stage);
4241

4342
private :
4443

45-
inline bool isReliable(pair<FacilityNode*, FacilityNode*> const & path) {
46-
if(reliable < 0) return true;
47-
else {
48-
const bool relp = isReliablePath(path.first, path.second);
49-
return reliable == 0 ? !relp : relp;
44+
inline bool isRLSelected(pair<FacilityNode*, FacilityNode*> const &path) {
45+
if(length_range.contains(path.second->getType()->getLevel() - path.first->getType()->getLevel())) {
46+
return reliable == 0 ? ! isReliablePath(path.first, path.second) :
47+
reliable > 0 ? isReliablePath(path.first, path.second) : true;
5048
}
51-
}
52-
53-
inline bool isInLength(pair<FacilityNode*, FacilityNode*> const & path) {
54-
return isInRange(path.second->getType()->getLevel() - path.first->getType()->getLevel(), length_range);
55-
}
49+
return false;
5650

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

6153
};

src/constraint_generation.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
int new_var = 0;
99
CUDFcoefficient min_bandwidth = 1; //set min_bandwidth to 1Ko
10+
CUDFcoefficient max_bandwidth = 5000; //set min_bandwidth to 1Ko
1011

1112
struct SetPathCoeff {
1213

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

115116
///////////
116117
//the number of provided connections is the sum of the numbers of local and outgoing connections.
117-
// for (int s = 0; s < problem->stageCount(); ++s) {
118-
// solver.new_constraint();
119-
// solver.set_constraint_coeff(problem->rankY(*i, s),1);
120-
// solver.set_constraint_coeff(problem->rankZ(*i, s), -1);
121-
// for(NodeIterator p = i->nbegin() ; p!= i->nend() ; p++) {
122-
// solver.set_constraint_coeff( problem->rankZ(*i, *p, s), 1);
123-
// }
124-
// solver.add_constraint_eq(i->getType()->getDemand(s));
125-
// }
118+
// for (int s = 0; s < problem->stageCount(); ++s) {
119+
// solver.new_constraint();
120+
// solver.set_constraint_coeff(problem->rankY(*i, s),1);
121+
// solver.set_constraint_coeff(problem->rankZ(*i, s), -1);
122+
// for(NodeIterator p = i->nbegin() ; p!= i->nend() ; p++) {
123+
// solver.set_constraint_coeff( problem->rankZ(*i, *p, s), 1);
124+
// }
125+
// solver.add_constraint_eq(i->getType()->getDemand(s));
126+
// }
126127

127128

128129

@@ -213,6 +214,8 @@ int generate_constraints(PSLProblem *problem, abstract_solver &solver, abstract_
213214
solver.set_constraint_coeff(problem->rankB(*i, *j, s), 1);
214215
solver.set_constraint_coeff(problem->rankZ(*i, *j, s), - min_bandwidth);
215216
solver.add_constraint_geq(0);
217+
///////////
218+
//TODO maximal bandwidth for a single connection
216219
}
217220
j++;
218221
}

src/constraint_generation.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919

2020
extern int new_var;
2121
extern CUDFcoefficient min_bandwidth;
22-
22+
extern CUDFcoefficient max_bandwidth;
2323

2424
// available criteria
25-
#define CRIT_DEFAULT 1
26-
#define CRIT_CONSERVATIVE 2
27-
#define CRIT_FRESHER 3
28-
#define CRIT_SFRESHER 4
29-
#define CRIT_FFRESHER 5
30-
#define CRIT_TFRESHER 5
31-
#define CRIT_PARANOID 6
32-
#define CRIT_TRENDY 7
33-
#define CRIT_TRENDY2 8
34-
#define CRIT_LEXPARANOID 9
35-
#define CRIT_LEXTRENDY 10
36-
#define CRIT_LEXTRENDY2 11
25+
//#define CRIT_DEFAULT 1
26+
//#define CRIT_CONSERVATIVE 2
27+
//#define CRIT_FRESHER 3
28+
//#define CRIT_SFRESHER 4
29+
//#define CRIT_FFRESHER 5
30+
//#define CRIT_TFRESHER 5
31+
//#define CRIT_PARANOID 6
32+
//#define CRIT_TRENDY 7
33+
//#define CRIT_TRENDY2 8
34+
//#define CRIT_LEXPARANOID 9
35+
//#define CRIT_LEXTRENDY 10
36+
//#define CRIT_LEXTRENDY2 11
3737

3838

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

0 commit comments

Comments
 (0)