-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDossMath11.java
More file actions
370 lines (331 loc) · 10.6 KB
/
Copy pathDossMath11.java
File metadata and controls
370 lines (331 loc) · 10.6 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import java.util.Iterator;
public class DossMath11 {
private static final double BASE = 3700;
private static final double PRIME = 45;
private static final double BONUS = 200;
private static final Relation COL = Io.chargerRelation("Col.rel");
private static final Relation FIN = Io.chargerRelation("Fin.rel");
private static final Relation CPT = Io.chargerRelation("Cpt.rel");
private static final Relation SUP = Io.chargerRelation("Sup.rel");
private static final Relation CCN = Io.chargerRelation("Ccn.rel");
private static final Relation SEX = Io.chargerRelation("Sex.rel");
private static final String[] tPers = Io.chargerDta("Pers.dta");
private static final int nbPers = Integer.parseInt(tPers[0]); // nombre de
// membres
// du
// personnel
private static final String[] tProj = Io.chargerDta("Proj.dta");
private static final int nbProj = Integer.parseInt(tProj[0]); // nombre
// d'options
private static final String[] tQual = Io.chargerDta("Qual.dta");
private static final int nbQual = Integer.parseInt(tQual[0]);// nombre de
// cours
private static Ensemble chercheurs = COL.domaine();
private static Ensemble administratifs = administratifs();
// Pas encore utilisé
// private static Ensemble financiers = FIN.domaine();
// LAP - Liste d'affectation possible
private static Relation LAP = CCN.reciproque().apres(CPT);
// Nombre de personne affectable par projet
private static Ordre PVP = ex2_3();
// PDG de l'entreprise
private static Elt PDG = ex3_3();
// Pondération correspondant à la relation SUP
private static int[] rang = ponderationSUP();
public static void main(String[] args) throws MathException {
// ex1_1();
// ex1_2();
// ex1_3();
// ex1_4();
// ---------------
// ex2_1();
// ex2_2();
// ex2_3();
// ex2_4();
// ex2_5();
// ex2_6();
// ---------------
// ex3_1();
// ex3_2();
ex3_3();
// ex3_4();
// ---------------
ex4_1();
// ex4_2();
// ---------------
// ex6_1();
ex6_2();
// ex6_3();
} // main
// Chaque membre du personnel à au moins un sexe...
public static Ensemble administratifs() {
Ensemble tmp = SEX.clone().domaine();
tmp.enlever(chercheurs);
return tmp;
}
public static void ex1_1() {
System.out.println("Liste des chercheurs");
lister(chercheurs, "PERSONNELS");
}
public static void ex1_2() {
System.out.println("Liste des administratifs");
lister(administratifs, "PERSONNELS");
}
public static void ex1_3() {
// EN ATTENTE: classe application souhaitée
}
public static void ex1_4() {
System.out
.println("Chercheurs qui collaborent au maximum de projets : ");
Ensemble ensChercheurs = new Ensemble();
int nbProjets = 0;
Iterator<Elt> itChercheur = chercheurs.iterator();
while (itChercheur.hasNext()) {
Elt unChercheur = itChercheur.next();
if (COL.degreDeSortie(unChercheur) > nbProjets) {
ensChercheurs = new Ensemble();
nbProjets = COL.degreDeSortie(unChercheur);
ensChercheurs.ajouter(unChercheur);
} else if (COL.degreDeSortie(unChercheur) == nbProjets) {
ensChercheurs.ajouter(unChercheur);
}
}
lister(ensChercheurs, "PERSONNELS");
}
// ---------------------------------------------------------------------------
public static void ex2_1() {
System.out.println("Question 2 : ");
// Relation créé en global
// Relation LAP
}
public static void ex2_2() {
lister(LAP.imageReciproque(numéro("PAMAL", "PROJETS")), "PERSONNELS");
}
public static Ordre ex2_3() {
Ordre or = new Ordre(LAP.arrivee());
Iterator<Elt> it1 = or.arrivee().iterator();
Ensemble ens = LAP.arrivee().clone();
while (it1.hasNext()) {
Elt elt = it1.next();
Iterator<Elt> it2 = ens.iterator();
while (it2.hasNext()) {
Elt elt2 = it2.next();
if (LAP.degreDEntre(elt) < LAP.degreDEntre(elt2))
or.ajouter(new Couple(elt, elt2));
}
}
return or;
}
public static void ex2_4() {
System.out
.println("Certains projets ne sont pas comparables entre eux");
System.out
.println("(Ceux ayant le même nombres de personnels affectables)");
}
public static void ex2_5() {
System.out.println("Cette ordre est-t-il total : "
+ PVP.total(PVP.depart()));
}
public static void ex2_6() {
lister(PVP.minimaux(PVP.depart()), "PROJETS");
lister(CCN.imageDirecte(PVP.minimaux(PVP.depart())), "QUALIFICATIONS");
}
// ---------------------------------------------------------------------------
public static void ex3_1() {
Relation COMPE = CPT.apres(COL.reciproque()).clone();
System.out.println("Les projets sont-ils bien gérés : "
+ COMPE.arrivee().estEgalA(CCN.arrivee()));
}
public static void ex3_2() {
if (SUP.acyclique())
System.out.println("La relation SUP est bien acyclique");
else
System.out.println("La relation SUP n'est pas acyclique");
}
public static Elt ex3_3() {
Ordre or = new Ordre(SUP);
Elt min = or.minimum(or.depart());
if (min != null) {
System.out.print("PDG : ");
lister(new Ensemble(min), "PERSONNELS");
return min;
} else
System.out.println("L'entreprise n'a pas de PDG");
return null;
}
public static void ex3_4() {
boolean correct = true;
Iterator<Elt> it = LAP.image().iterator();
while (it.hasNext()) {
Elt projet = it.next();
if (!COL.imageReciproque(projet).inclusDans(
LAP.imageReciproque(projet)))
correct = false;
}
if (correct)
System.out.println("Tout est en ordre");
else
System.out
.println("Un chercheur participe à un projet auquel il ne devrait pas.");
}
// ---------------------------------------------------------------------------
public static void ex4_1() {
double salaire;
Iterator<Elt> itMembre = SEX.domaine().iterator();
while (itMembre.hasNext()) {
Elt membre = itMembre.next();
salaire = calculSalaire(membre);
lister(new Ensemble(membre), "PERSONNELS");
System.out.println("\t\t\t" + salaire + " euros");
}
}
// Pondération de la relation SUP afin d'accéder aisément au rang d'un membre
private static int[] ponderationSUP() {
Ordre or = new Ordre(SUP);
int[] rang = new int[or.depart().cardinal()+1];
Iterator<Elt> it = SUP.depart().iterator();
while (it.hasNext()) {
Elt rechercher = it.next();
int cpt = 0;
Elt superieurCourant = rechercher;
while (!superieurCourant.estEgalA(PDG)) {
Ensemble temp = SUP.imageReciproque(superieurCourant);
temp.enlever(superieurCourant);
Elt min = or.minimum(temp);
if (min == null) {
superieurCourant = or.minimaux(temp).unElement();
} else
superieurCourant = min;
cpt++;
}
rang[rechercher.val()] = cpt;
}
return rang;
}
// Calcul du salaire pour la question 4.1
private static double calculSalaire(Elt membre) {
double salaire = BASE;
double DELTA = 0.78;
double bonus = 0;
// On cherche le niveau du membre
int niveauMembre = rang[membre.val()];
// On calcule sa base
for (int i = 0; i < niveauMembre; i++)
salaire *= DELTA;
// Ensuite on calcule la PRIME en fonction du nombre de personnes
// auxquelles on est supérieur
salaire += PRIME * (SUP.imageDirecte(membre).cardinal());
// Et on ajoute le BONUS de chaque projet auxquel il participe
Ensemble projetsDuMembre = FIN.imageDirecte(membre);
projetsDuMembre = Ensemble.intersection(projetsDuMembre, FIN.image());
Iterator<Elt> itProjet = projetsDuMembre.iterator();
while (itProjet.hasNext()) {
Elt projet = itProjet.next();
bonus += COL.imageReciproque(projet).cardinal() * BONUS / FIN.imageReciproque(projet).cardinal();
}
salaire += bonus;
salaire *= 100;
salaire = Math.round(salaire);
return salaire / 100;
}
public static void ex4_2() {
}
// ---------------------------------------------------------------------------
public static void ex6_1() {
Iterator<Elt> it = CCN.depart().iterator();
while (it.hasNext()) {
Elt e = it.next();
System.out.println("Electeur du projet " + e.val() + " "
+ tProj[e.val()] + " :");
electeur(e);
}
}
public static void ex6_2() {
Relation rel = FIN.apres(COL.reciproque());
if (rel.reflexive())
System.out
.println("Tous les projets ont au moins un parrain possible");
else {
System.out.println(rel);
Ensemble projetSansParrainsPossible = new Ensemble();
Iterator<Elt> it = rel.depart().iterator();
while (it.hasNext()) {
Elt elt = it.next();
if (!rel.contient(elt, elt))
projetSansParrainsPossible.ajouter(elt);
}
lister(projetSansParrainsPossible, "PROJETS");
}
}
public static void ex6_3() {
// FAUX
Ensemble parrain = Ensemble.intersection(FIN.domaine(), COL.domaine());
// ensuite voir ceux qui sont les seul de leur projet
Iterator<Elt> it = FIN.arrivee().iterator();
while (it.hasNext()) {
Elt x = it.next();
Ensemble a = FIN.imageReciproque(x).inter(parrain);
Ensemble b = COL.imageReciproque(x).inter(parrain);
if (a.cardinal() != 1)
parrain.enlever(a);
if (b.cardinal() != 1)
parrain.enlever(b);
}
lister(parrain, "PERSONNELS");
}
private static void electeur(Elt projet) {
Ordre SUP2 = new Ordre(SUP);
Ensemble electeur = new Ensemble();
Ensemble temp = COL.imageReciproque(projet).union(
FIN.imageReciproque(projet));
electeur.ajouter(temp);
electeur.ajouter(SUP2.getRel().imageReciproque(temp));
lister(electeur, "PERSONNELS");
}
// affiche à l'écran les éléments de e, interprétés selon contexte
private static void lister(Ensemble e, String contexte)
throws MathException {
String[] t;
String ct;
if (contexte.toUpperCase().equals("PERSONNELS")) {
t = tPers;
ct = "de membres du personnel";
} else if (contexte.toUpperCase().equals("PROJETS")) {
t = tProj;
ct = "de projets";
} else if (contexte.toUpperCase().equals("QUALIFICATIONS")) {
t = tQual;
ct = "de domaines de qualification";
} else
throw new MathException("contexte incorrect");
if (e.estVide())
System.out.println("Ensemble vide " + ct);
else {
Iterator<Elt> eit = e.iterator();
while (eit.hasNext()) {
int x = eit.next().val();
System.out.println(" " + x + "\t" + t[x]);
}
}
} // lister
// renvoie le Elt correpondant à nom, d'après contexte; null si incorrect
private static Elt numéro(String nom, String contexte) throws MathException {
String[] t;
int stop;
if (contexte.toUpperCase().equals("PERSONNELS")) {
t = tPers;
stop = nbPers;
} else if (contexte.toUpperCase().equals("PROJETS")) {
t = tProj;
stop = nbProj;
} else if (contexte.toUpperCase().equals("QUALIFICATIONS")) {
t = tQual;
stop = nbQual;
} else
throw new MathException("contexte incorrect");
for (int i = 1; i <= stop; i++)
if (t[i].toUpperCase().equals(nom.toUpperCase()))
return new Elt(i);
return null;
} // numéro
} // class