-
Notifications
You must be signed in to change notification settings - Fork 1
/
contrainte.cpp
90 lines (81 loc) · 2.19 KB
/
contrainte.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
#include "contrainte.h"
using namespace std;
double Operation::apply(double a, double b) const{
if (op == "+"){
return a+b;
}
if (op == "-"){
return a-b;
}
if (op == "*"){
return a*b;
}
if (op == "/"){
return a/b;
}
else {
throw invalid_argument(op);
}
}
bool Comparaison::apply(double a, double b) const{
if (comp == "="){
return a==b;
}
if (comp == "!="){
return a != b;
}
if (comp == "<="){
return a <= b;
}
if (comp == ">="){
return a >= b;
}
if (comp == "<"){
return a < b;
}
if (comp == ">"){
return a > b;
}
if (comp == "=|"){
return (a == b or a == abs (b));
}
else {
throw invalid_argument(comp);
}
}
Contrainte::Contrainte(const int v1, const vector<int> dom1, const int v2, const vector<int> dom2){
var1 = v1;
var2 = v2;
for (auto i : dom1){
for (auto j : dom2){
c.insert(pair<int,int>{i,j});
}
}
}
void Contrainte::ajoute_relation(const int value1, const int value2){
c.insert(pair<int,int>(value1,value2)); // les sets n'ajoutent pas si ce n'est pas dedans
}
void Contrainte::supprime_relation(const int value1, const int value2){
c.erase(pair<int,int>(value1,value2)); // pas de pbs non plus
}
void Contrainte::ajoute_relations(double coef1, const vector<int> dom1, string ope, double coef2, const vector<int> dom2, string compa, double valeur){
for (auto i : dom1){
for (auto j : dom2){
if (Comparaison(compa).apply(Operation(ope).apply(coef1*i,coef2*j),valeur)){
c.insert(pair<int,int>{i,j});
}
}
}
}
void Contrainte::supprime_relations(double coef1, const vector<int> dom1, string ope, double coef2, const vector<int> dom2, string compa, double valeur){
for (auto i : dom1){
for (auto j : dom2){
if (not Comparaison(compa).apply(Operation(ope).apply(coef1*i,coef2*j),valeur)){
c.erase(pair<int,int>{i,j});
}
}
}
}
bool Contrainte::satisfaite(const int v1, const int v2) const{
return(c.find(pair<int,int>(v1,v2)) != c.end());
}