-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchampSolution.cpp
156 lines (130 loc) · 4.19 KB
/
champSolution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright 2016 <copyright holder> <email>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "champSolution.h"
using namespace std;
champSolution::champSolution()
{
}
champSolution::champSolution(const champSolution& ch)
{
champ_solutions= ch.getSolutions();
}
void champSolution::ajoutSolution(const Solution& solution)
{
champ_solutions.push_back(solution);
}
Solution champSolution::getBestSolution() const
{
Solution tmp_best_sol= champ_solutions[0];
for(unsigned int i= 1; i < champ_solutions.size(); ++i){
if(champ_solutions[i].get_obj() > tmp_best_sol.get_obj()){
tmp_best_sol= champ_solutions[i];
};
}
return tmp_best_sol;
}
bool champSolution::dominationSol(const Solution& sol1, const Solution& sol2, bool maxA, bool maxB)
{
if(0 == maxA) //on veut minimiser l'objectif A
{
if(0 == maxB)//on veut minimiser l'objectif B
{
return (sol1.get_objA() < sol2.get_objA() && sol1.get_objB() < sol2.get_objB());
} else //on veut maximiser l'objectif B
{
return (sol1.get_objA() < sol2.get_objA() && sol1.get_objB() > sol2.get_objB());
}
} else //on veut maximiser l'objectif A
{
if(0 == maxB) //on veut minimiser l'objectif B
{
return (sol1.get_objA() > sol2.get_objA() && sol1.get_objB() < sol2.get_objB());
} else //on veut maximiser l'objectif B
{
return (sol1.get_objA() > sol2.get_objA() && sol1.get_objB() > sol2.get_objB());
}
}
}
bool champSolution::dominationComplete(const Solution& sol, bool maxA, bool maxB)
{
bool res= true;
for(unsigned int i= 0; i < champ_solutions.size(); ++i){
//si ne serait-ce qu'une solution du champ des solution domine complètement "sol", sol n'est pas dominante
if(dominationSol(champ_solutions[i], sol, maxA, maxB)) return false;
}
return res;
}
bool champSolution::areIncomparable(const Solution& sol1, const Solution& sol2)
{
return (((sol1.get_objA() > sol2.get_objA()) && (sol1.get_objB() < sol2.get_objB())) ||
((sol1.get_objA() < sol2.get_objA()) && (sol1.get_objB() > sol2.get_objB())));
}
vector< Solution > champSolution::getFront(bool maxA, bool maxB)
{
vector<Solution>::iterator it;
vector<Solution> front;
for(it= champ_solutions.begin(); it != champ_solutions.end(); ++it){
if(dominationComplete(*it, maxA, maxB)){
front.push_back(*it);
} else {
}
}
return front;
}
std::vector<Solution> champSolution::addSolSupprAllWeaks(vector<Solution> front, const Solution& sol, bool maxA, bool maxB)
{
std::vector<Solution> res;
for(unsigned int i= 0; i < front.size(); ++i){
if(dominationSol(sol, front[i], maxA, maxB)){
// solution dominee, pas d'ajout
} else {
res.push_back(front[i]);
}
}
res.push_back(sol);
return res;
}
bool champSolution::wouldBeDominated(const vector< Solution >& ens_sol, const Solution& sol, int maxA, int maxB)
{
bool res= false;
for(unsigned int i= 0; i < ens_sol.size(); ++i){
if(dominationSol(ens_sol[i], sol, maxA, maxB)) return true;
}
return res;
}
vector< Solution > champSolution::buildingFront(bool maxA, bool maxB)
{
vector<Solution> front;
vector<Solution>::iterator it;
for(it= champ_solutions.begin(); it != champ_solutions.end(); ++it){
if(front.empty()) front.push_back(*it);
if(!wouldBeDominated(front, *it, maxA, maxB)) //la solution it peut etre ajoutee au front
{
// front.push_back(*it);
//supprimer les solutions devenues faibles !
front= addSolSupprAllWeaks(front, (*it), maxA, maxB);
}
}
return front;
}
ostream& champSolution::print(ostream& out) const
{
for(unsigned int i= 0; i < champ_solutions.size(); ++i){
out << champ_solutions[i] << endl;
}
return out;
}