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
dd934483
Commit
dd934483
authored
2 years ago
by
juliano.souzaluz
Browse files
Options
Downloads
Patches
Plain Diff
correction d'un premier bug
parent
25cd95d8
No related branches found
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
+50
-23
50 additions, 23 deletions
src/Simplex.java
with
50 additions
and
23 deletions
src/Simplex.java
+
50
−
23
View file @
dd934483
...
...
@@ -7,6 +7,7 @@ public class Simplex {
private
int
x
;
private
int
y
;
private
int
nbPivot
;
private
static
double
EPSILON
=
0
E
-
7
;
public
Matrix
getTabAux
()
{
return
tabAux
;
...
...
@@ -88,24 +89,40 @@ public class Simplex {
}
}
this
.
tabAux
.
matrixPrint
(
"Tableau auxiliaire "
,
2
);
double
valLastCase
=
this
.
tabAux
.
getData
(
this
.
tabAux
.
getX
()
-
1
,
this
.
tabAux
.
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
(
valLastCase
<
0
)
{
pivot
(
tabAux
);
System
.
out
.
println
(
"Nombre de pivot: "
+
getNbPivot
());
/*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
(
valLastCas
e
>
0
)
{
} else if (
solutionOptimal
e > 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
);
}
/*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
)
{
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
if
(
signe
(
mat
.
getData
(
this
.
x
,
j
)))
return
j
;
for
(
int
j
=
0
;
j
<
mat
.
getY
()
;
j
++)
{
if
(
signe
(
mat
.
getData
(
mat
.
getX
()
-
1
,
j
)))
return
j
;
}
return
-
1
;
}
...
...
@@ -116,36 +133,46 @@ public class Simplex {
if
(
firstNeg
==
-
1
)
return
;
// si pas de négatif
boolean
has_neg
=
false
;
int
id
=
ligneSortante
(
mat
,
firstNeg
);
double
pivot
=
mat
.
getData
(
id
,
firstNeg
);
for
(
int
i
=
0
;
i
<
this
.
y
;
i
++)
{
mat
.
setData
(
id
,
i
,
mat
.
getData
(
id
,
i
)
/
pivot
);
double
val_
pivot
=
mat
.
getData
(
id
,
firstNeg
);
for
(
int
i
=
0
;
i
<
mat
.
getY
()
;
i
++)
{
mat
.
setData
(
id
,
i
,
mat
.
getData
(
id
,
i
)
/
val_
pivot
);
}
for
(
int
i
=
0
;
i
<
this
.
x
+
1
;
i
++)
{
pivot
=
mat
.
getData
(
i
,
firstNeg
);
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
for
(
int
i
=
0
;
i
<
mat
.
getX
()
;
i
++)
{
val_
pivot
=
mat
.
getData
(
i
,
firstNeg
);
for
(
int
j
=
0
;
j
<
mat
.
getY
()
;
j
++)
{
if
(
i
!=
id
)
{
mat
.
setData
(
i
,
j
,
mat
.
getData
(
i
,
j
)
-
pivot
*
mat
.
getData
(
id
,
j
));
mat
.
setData
(
i
,
j
,
mat
.
getData
(
i
,
j
)
-
val_
pivot
*
mat
.
getData
(
id
,
j
));
}
}
}
mat
.
matrixPrint
(
"Pivot numéro "
+
this
.
nbPivot
,
2
);
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
if
(
signe
(
mat
.
getData
(
this
.
x
,
j
)))
{
//
mat.matrixPrint("Pivot numéro " + this.nbPivot, 2);
for
(
int
j
=
0
;
j
<
mat
.
getY
()
;
j
++)
if
(
signe
(
mat
.
getData
(
mat
.
getX
()
-
1
,
j
)))
{
has_neg
=
true
;
if
(
has_neg
)
{
break
;
}
}
if
(
has_neg
)
pivot
(
mat
);
}
int
ligneSortante
(
Matrix
mat
,
int
y
)
{
int
id
=
0
;
double
tmp
=
mat
.
getData
(
id
,
this
.
y
-
1
)
/
mat
.
getData
(
id
,
y
);
for
(
int
i
=
1
;
i
<
this
.
x
-
1
;
i
++)
{
double
tmp_s
=
mat
.
getData
(
i
,
this
.
y
-
1
)
/
mat
.
getData
(
i
,
y
);
if
(
tmp_s
<
tmp
)
{
id
=
i
;
tmp
=
tmp_s
;
while
(
mat
.
getData
(
id
,
y
)
<
0
)
{
id
++;
}
double
tmp
=
mat
.
getData
(
id
,
mat
.
getY
()
-
1
)
/
mat
.
getData
(
id
,
y
);
double
tmp_s
;
for
(
int
i
=
1
;
i
<
mat
.
getX
()
-
1
;
i
++)
{
if
(
mat
.
getData
(
i
,
y
)
>
0
)
{
tmp_s
=
mat
.
getData
(
i
,
mat
.
getY
()
-
1
)
/
mat
.
getData
(
i
,
y
);
if
(
tmp_s
<
tmp
)
{
id
=
i
;
tmp
=
tmp_s
;
}
}
}
return
id
;
...
...
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