Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp-math
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Math
2e-annee
tp-math
Commits
5c98ea4e
Commit
5c98ea4e
authored
2 years ago
by
juliano.souzaluz
Browse files
Options
Downloads
Patches
Plain Diff
Update Simplex.java
fin de phase terminée, à revoir : couts et autres problèmes
parent
8fdd310f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Simplex.java
+27
-32
27 additions, 32 deletions
src/Simplex.java
with
27 additions
and
32 deletions
src/Simplex.java
+
27
−
32
View file @
5c98ea4e
...
...
@@ -8,6 +8,7 @@ public class Simplex {
private
int
y
;
private
int
nbPivot
;
private
static
double
EPSILON
=
0
E
-
7
;
private
int
nbContraintes
;
public
Matrix
getTabAux
()
{
return
tabAux
;
...
...
@@ -21,13 +22,14 @@ public class Simplex {
return
nbPivot
;
}
public
Simplex
(
int
x
,
int
y
,
int
nbSousCondition
)
{
public
Simplex
(
int
x
,
int
y
,
int
nbSousCondition
,
int
nbContraintes
)
{
this
.
x
=
x
;
this
.
y
=
y
;
this
.
matEcart
=
new
Matrix
(
x
,
y
);
this
.
nbSousCondition
=
nbSousCondition
;
this
.
tabAux
=
new
Matrix
(
x
+
2
,
y
+
nbSousCondition
+
1
);
this
.
nbPivot
=
0
;
this
.
nbContraintes
=
nbContraintes
;
}
void
createSimplex
(
Equation
eq
,
int
nbContraintes
)
{
...
...
@@ -66,6 +68,7 @@ public class Simplex {
}
void
tabAux
(
int
line
)
{
// TODO : A REVOIR CETTE PARTIE
double
[]
tabRes
=
new
double
[
this
.
y
+
this
.
nbSousCondition
+
1
];
Arrays
.
fill
(
tabRes
,
1.0
);
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
...
...
@@ -73,11 +76,17 @@ public class Simplex {
double
res
=
this
.
matEcart
.
getData
(
line
,
j
)
*
-
1
;
this
.
matEcart
.
setData
(
line
,
j
,
res
);
}
for
(
int
i
=
0
;
i
<
this
.
x
;
i
++)
double
tmpSum
=
0
;
for
(
int
i
=
0
;
i
<
this
.
x
;
i
++)
{
//tabRes[j] -= Math.abs(this.matEcart.getData(i, j));
tabRes
[
j
]
-=
this
.
matEcart
.
getData
(
i
,
j
);
tabRes
[
j
]
-=
1
;
tmpSum
+=
-
1
*
this
.
matEcart
.
getData
(
i
,
j
);
//tabRes[j] -= this.matEcart.getData(i, j);
}
tabRes
[
j
]
=
tmpSum
;
System
.
out
.
print
(
tmpSum
+
" "
);
}
System
.
out
.
println
();
// FIN DU TODO
// -2 car => tabRes[(tabRes.length-1) - (this.nbSousCondition - 1)];
tabRes
[
tabRes
.
length
-
1
]
=
tabRes
[
tabRes
.
length
-
this
.
nbSousCondition
-
2
];
...
...
@@ -94,37 +103,23 @@ public class Simplex {
this
.
tabAux
.
setData
(
i
,
j
,
this
.
matEcart
.
getData
(
i
,
j
-
this
.
matEcart
.
getX
()));
}
}
this
.
tabAux
.
matrixPrint
(
"Tableau auxiliaire
"
,
2
);
this
.
tabAux
.
printTabAux
(
"Tableau auxiliaire
"
,
this
.
nbContraintes
,
this
.
nbSousCondition
,
this
.
tabAux
.
getY
()
-
this
.
matEcart
.
getY
()
-
1
);
pivot
(
this
.
tabAux
);
double
solutionOptimale
=
this
.
tabAux
.
getData
(
this
.
tabAux
.
getX
()
-
1
,
this
.
tabAux
.
getY
()
-
1
);
// si la dernière case est négative, il faut envoyer le tableau "basique" dans la méthode du pivot
/*if (solutionOptimale < 0) {
Matrix newMat = this.matEcart; // pour récupérer les bonnes tailles initiales
newMat.matrixFill(newMat.getX(), newMat.getY(), tabAux.getDatas());
pivot(newMat);
} else if (solutionOptimale > 0) {
// si elle est positive , il n'y a pas de solutions admissibles
System.out.println("Il n'y a pas de solutions admissibles pour ce problème");
} else // = 0
{
System.out.println("Le min/max est 0");
}*/
if
(
solutionOptimale
>
0
)
{
System
.
out
.
println
(
"Il n'y a pas de solutions admissibles pour ce problème"
);
}
else
{
Matrix
newMat
=
this
.
matEcart
;
// pour récupérer les bonnes tailles initiales
newMat
.
matrixFill
(
newMat
.
getX
(),
newMat
.
getY
(),
tabAux
.
getDatas
());
//newMat.matrixPrint("Nouvelle matrice ", 3);
this
.
nbPivot
=
0
;
pivot
(
newMat
);
newMat
.
matrixPrint
(
"Résultat"
,
3
);
if
(
solutionOptimale
>
0
+
EPSILON
)
{
System
.
out
.
println
(
"Il n'y a pas de solutions admissibles pour ce problème."
);
}
if
(
solutionOptimale
==
0
)
{
// Il y a une solution optimale
// Il faut enlever les variables auxilaires
Matrix
res
=
new
Matrix
(
matEcart
.
getX
(),
matEcart
.
getY
());
res
.
matrixFill
(
res
.
getX
(),
res
.
getY
(),
tabAux
.
getDatas
());
res
.
matrixPrint
(
"Petit tableau"
,
2
);
nbPivot
=
0
;
pivot
(
res
);
res
.
matrixPrint
(
"Résultat "
,
3
);
System
.
out
.
println
(
"Nombre de pivot : "
+
nbPivot
);
}
/*if (solutionOptimale <= EPSILON + 0 || solutionOptimale >= 0 - EPSILON) {
// il faut s'assurer que la base ne contient aucune variable auxiliaire
System.out.println("il faut s'assurer que la base ne contient aucune variable auxiliaire");
}*/
}
int
getFirstNeg
(
Matrix
mat
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment