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
f782af20
Commit
f782af20
authored
2 years ago
by
juliano.souzaluz
Browse files
Options
Downloads
Patches
Plain Diff
mode debug et autre
parent
30c5b718
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Main.java
+20
-9
20 additions, 9 deletions
src/Main.java
src/Simplex.java
+21
-14
21 additions, 14 deletions
src/Simplex.java
with
41 additions
and
23 deletions
src/Main.java
+
20
−
9
View file @
f782af20
...
...
@@ -38,13 +38,21 @@ public class Main {
* @param args arguments en entrées
*/
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
,
RuntimeException
{
long
start
=
System
.
nanoTime
();
Scanner
readFile
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Entrez le nom du fichier à tester, il doit se situer dans le dossier src."
);
//String nameFile = readFile.nextLine();
String
nameFile
=
"network2.txt"
;
//String nameFile = "input.txt";
File
f
=
new
File
(
"src/"
+
nameFile
);
System
.
out
.
println
(
"Entrez le nom du fichier à tester SANS EXTENSION, il doit se situer dans le dossier src. (Ex: input)"
);
String
nameFile
=
readFile
.
nextLine
();
File
f
=
new
File
(
"src/"
+
nameFile
+
".txt"
);
System
.
out
.
println
(
"Souhaitez vous activer le débogage ? y / n"
);
String
readingDebug
=
readFile
.
nextLine
();
boolean
debugging
=
false
;
switch
(
readingDebug
)
{
case
"y"
->
debugging
=
true
;
case
"n"
->
debugging
=
false
;
default
->
System
.
err
.
println
(
"Une erreur a été détectée lors de la saisie du débogage"
);
}
long
start
=
System
.
nanoTime
();
Scanner
sc
=
new
Scanner
(
f
);
String
[]
elements
;
int
sousCondition
=
nbSc
(
sc
),
line
=
0
;
...
...
@@ -78,7 +86,8 @@ public class Main {
eq
.
printEq
();
// Tableau initial
Simplex
spx
=
new
Simplex
(
eq
.
getMat
().
getLine
(),
eq
.
getMat
().
getLine
()
+
eq
.
getMat
().
getCol
()
+
1
,
line
,
contraintes
);
Simplex
spx
=
new
Simplex
(
eq
.
getMat
().
getLine
(),
eq
.
getMat
().
getLine
()
+
eq
.
getMat
().
getCol
()
+
1
,
line
,
contraintes
,
debugging
);
spx
.
createSimplex
(
eq
,
contraintes
);
spx
.
printSimplex
(
spx
.
getMatEcart
(),
"Tableau initial"
);
...
...
@@ -87,8 +96,10 @@ public class Main {
spx
.
tabAux
();
}
else
{
spx
.
pivot
(
spx
.
getMatEcart
(),
false
);
spx
.
printSimplex
(
spx
.
getMatEcart
(),
"Résultat"
);
System
.
out
.
println
(
"Nombre de pivot: "
+
spx
.
getNbPivot
());
if
(
debugging
)
{
spx
.
printSimplex
(
spx
.
getMatEcart
(),
"Résultat"
);
System
.
out
.
println
(
"Nombre de pivot: "
+
spx
.
getNbPivot
());
}
}
sc
.
close
();
...
...
This diff is collapsed.
Click to expand it.
src/Simplex.java
+
21
−
14
View file @
f782af20
import
java.util.Arrays
;
public
class
Simplex
{
private
boolean
debugging
;
private
Matrix
matEcart
;
private
Matrix
tabAux
;
private
int
nbSousCondition
;
...
...
@@ -18,7 +19,7 @@ public class Simplex {
return
nbPivot
;
}
public
Simplex
(
int
ligne
,
int
colonne
,
int
nbSousCondition
,
int
nbContraintes
)
{
public
Simplex
(
int
ligne
,
int
colonne
,
int
nbSousCondition
,
int
nbContraintes
,
boolean
debugging
)
{
this
.
ligne
=
ligne
;
this
.
colonne
=
colonne
;
this
.
matEcart
=
new
Matrix
(
ligne
,
colonne
);
...
...
@@ -26,6 +27,7 @@ public class Simplex {
this
.
tabAux
=
new
Matrix
(
ligne
+
2
,
colonne
+
nbSousCondition
+
1
);
this
.
nbPivot
=
0
;
this
.
nbContraintes
=
nbContraintes
;
this
.
debugging
=
debugging
;
}
void
createSimplex
(
Equation
eq
,
int
nbContraintes
)
{
...
...
@@ -63,7 +65,7 @@ public class Simplex {
}
void
tabAux
()
{
System
.
out
.
println
();
if
(
debugging
)
System
.
out
.
println
();
double
[]
tabRes
=
new
double
[
this
.
colonne
+
this
.
nbSousCondition
+
1
];
Arrays
.
fill
(
tabRes
,
1.0
);
for
(
int
i
=
0
;
i
<
this
.
colonne
;
i
++)
{
...
...
@@ -98,7 +100,9 @@ public class Simplex {
}
}
}
this
.
tabAux
.
printTabAux
(
"Tableau auxiliaire"
,
this
.
nbContraintes
,
this
.
nbSousCondition
,
this
.
tabAux
.
getCol
()
-
this
.
matEcart
.
getCol
()
-
1
);
if
(
debugging
)
this
.
tabAux
.
printTabAux
(
"Tableau auxiliaire"
,
this
.
nbContraintes
,
this
.
nbSousCondition
,
this
.
tabAux
.
getCol
()
-
this
.
matEcart
.
getCol
()
-
1
);
pivot
(
this
.
tabAux
,
true
);
double
solutionOptimale
=
this
.
tabAux
.
getData
(
this
.
tabAux
.
getLine
()
-
1
,
this
.
tabAux
.
getCol
()
-
1
);
if
(
solutionOptimale
>
0
+
EPSILON
)
{
...
...
@@ -109,11 +113,13 @@ public class Simplex {
// Il faut enlever les variables auxilaires
Matrix
res
=
new
Matrix
(
matEcart
.
getLine
(),
matEcart
.
getCol
());
res
.
matrixFill
(
res
.
getLine
(),
res
.
getCol
(),
tabAux
.
getDatas
());
res
.
matrixPrint
(
"Petit tableau"
);
if
(
debugging
)
res
.
matrixPrint
(
"Petit tableau"
);
nbPivot
=
0
;
pivot
(
res
,
true
);
res
.
matrixPrint
(
"Résultat "
);
System
.
out
.
println
(
"Nombre de pivot : "
+
nbPivot
);
if
(
debugging
)
{
res
.
matrixPrint
(
"Matrice Résultat "
);
System
.
out
.
println
(
"Nombre de pivot : "
+
nbPivot
);
}
}
}
...
...
@@ -125,8 +131,8 @@ public class Simplex {
}
/**
* @param mat
* @param phase
true => phase 1 | false => phase 2
* @param mat
Matrix
* @param phase true => phase 1 | false => phase 2
*/
void
pivot
(
Matrix
mat
,
boolean
phase
)
{
this
.
nbPivot
+=
1
;
...
...
@@ -148,10 +154,12 @@ public class Simplex {
}
}
}
mat
.
matrixPrint
(
"Pivot numéro "
+
this
.
nbPivot
);
System
.
out
.
println
(
"colonne du pivot: "
+
firstNeg
);
System
.
out
.
println
(
"ligne du pivot: "
+
id
);
System
.
out
.
println
(
"Valeur du pivot: "
+
val_pivot
);
if
(
debugging
)
{
mat
.
matrixPrint
(
"Pivot numéro "
+
this
.
nbPivot
);
System
.
out
.
println
(
"colonne du pivot: "
+
firstNeg
);
System
.
out
.
println
(
"ligne du pivot: "
+
id
);
System
.
out
.
println
(
"Valeur du pivot: "
+
val_pivot
);
}
for
(
int
j
=
0
;
j
<
mat
.
getCol
();
j
++)
if
(
signe
(
mat
.
getData
(
mat
.
getLine
()
-
1
,
j
)))
{
has_neg
=
true
;
...
...
@@ -159,11 +167,10 @@ public class Simplex {
}
if
(
has_neg
)
pivot
(
mat
,
phase
);
}
int
ligneSortante
(
Matrix
mat
,
int
y
,
boolean
phase
)
{
int
depth
=
phase
?
mat
.
getLine
()
-
2
:
mat
.
getLine
()
-
1
;
int
depth
=
phase
?
mat
.
getLine
()
-
2
:
mat
.
getLine
()
-
1
;
int
id
=
0
;
while
(!(
mat
.
getData
(
id
,
y
)
>
0
)
&&
mat
.
getData
(
id
,
depth
)
>=
0
)
{
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