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
a008e66b
Commit
a008e66b
authored
2 years ago
by
thibault.capt
Browse files
Options
Downloads
Patches
Plain Diff
debug
parent
5f2c9aaa
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Equation.java
+9
-0
9 additions, 0 deletions
src/Equation.java
src/Main.java
+7
-4
7 additions, 4 deletions
src/Main.java
src/Simplex.java
+22
-10
22 additions, 10 deletions
src/Simplex.java
src/input.txt
+2
-1
2 additions, 1 deletion
src/input.txt
with
40 additions
and
15 deletions
src/Equation.java
+
9
−
0
View file @
a008e66b
...
...
@@ -169,6 +169,15 @@ public class Equation {
return
line
;
}
public
int
getNbLineMat
()
{
for
(
int
i
=
0
;
i
<
7
;
i
++)
{
for
(
int
j
=
0
;
j
<
nbContraintes
;
j
++)
{
}
}
return
0
;
}
/**
* Print les vecteurs et la matrice
*/
...
...
This diff is collapsed.
Click to expand it.
src/Main.java
+
7
−
4
View file @
a008e66b
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.util.Arrays
;
import
java.util.Scanner
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -71,16 +72,18 @@ public class Main {
eq
.
printEq
(
line
);
// Tableau initiale
Simplex
spx
=
new
Simplex
(
4
,
6
);
Simplex
spx
=
new
Simplex
(
line
+
1
,
line
+
3
);
spx
.
createMatEcart
(
eq
);
spx
.
printSimplex
(
"Tableau"
);
//System.out.println(Arrays.deepToString(spx.getMatEcart()));
// true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible
if
(
spx
.
which_phase
())
spx
.
tabAux
();
else
spx
.
pivot
(
0
);
spx
.
printSimplex
(
"pivot"
);
else
{
spx
.
pivot
();
spx
.
printSimplex
(
"pivot"
);
}
sc
.
close
();
}
catch
(
FileNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
...
...
This diff is collapsed.
Click to expand it.
src/Simplex.java
+
22
−
10
View file @
a008e66b
...
...
@@ -3,6 +3,10 @@ public class Simplex {
private
final
int
x
;
private
final
int
y
;
public
Double
[][]
getMatEcart
()
{
return
matEcart
;
}
public
void
setMatEcartById
(
Double
d
,
int
x
,
int
y
)
{
matEcart
[
x
][
y
]
=
d
;
}
...
...
@@ -39,7 +43,7 @@ public class Simplex {
}
// Membre de droite
for
(
int
i
=
0
;
i
<=
nbContraintes
;
i
++)
for
(
int
i
=
0
;
i
<=
x
-
2
;
i
++)
setMatEcartById
(
eq
.
getRightVec
().
get
(
i
),
i
,
y
-
1
);
// Fonction obj
...
...
@@ -55,10 +59,10 @@ public class Simplex {
* @return true = phase 1 | false = phase 2
*/
boolean
which_phase
(){
boolean
res
=
tru
e
;
boolean
res
=
fals
e
;
for
(
int
i
=
0
;
i
<
x
;
i
++)
{
if
(
signe
(
matEcart
[
i
][
y
-
1
]))
res
=
fals
e
;
if
(
!
signe
(
matEcart
[
i
][
y
-
1
]))
res
=
tru
e
;
}
return
res
;
}
...
...
@@ -66,15 +70,24 @@ public class Simplex {
}
void
pivot
(
int
y
)
{
int
getFirstNeg
()
{
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
if
(!
signe
(
matEcart
[
x
-
1
][
j
]))
return
j
;
}
return
-
1
;
}
void
pivot
()
{
int
firstNeg
=
getFirstNeg
();
if
(
firstNeg
==
-
1
)
return
;
boolean
has_neg
=
false
;
int
id
=
ligneSortante
(
y
);
double
pivot
=
this
.
matEcart
[
id
][
y
];
int
id
=
ligneSortante
(
firstNeg
);
double
pivot
=
this
.
matEcart
[
id
][
firstNeg
];
for
(
int
i
=
0
;
i
<
this
.
y
;
i
++)
{
this
.
matEcart
[
id
][
i
]
/=
pivot
;
}
for
(
int
i
=
0
;
i
<
this
.
x
;
i
++)
{
pivot
=
this
.
matEcart
[
i
][
y
];
pivot
=
this
.
matEcart
[
i
][
firstNeg
];
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
if
(
i
!=
id
)
{
this
.
matEcart
[
i
][
j
]
-=
pivot
*
this
.
matEcart
[
id
][
j
];
...
...
@@ -84,9 +97,8 @@ public class Simplex {
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
if
(!
signe
(
this
.
matEcart
[
x
-
1
][
j
]))
{
has_neg
=
true
;
y
=
j
;
}
if
(
has_neg
)
pivot
(
y
);
if
(
has_neg
)
pivot
();
}
...
...
This diff is collapsed.
Click to expand it.
src/input.txt
+
2
−
1
View file @
a008e66b
max;8;9;
2;5;<=;12;
50;5;<=;150;
5;50;<=;100;
\ No newline at end of file
5;50;<=;100;
1;2;<=;-1;
\ No newline at end of file
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