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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Math
2e-annee
tp-math
Commits
734a0c98
Commit
734a0c98
authored
2 years ago
by
thibault.capt
Browse files
Options
Downloads
Patches
Plain Diff
change code for list
parent
52fcbd6b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Main.java
+5
-5
5 additions, 5 deletions
src/Main.java
src/Simplex2.java
+110
-3
110 additions, 3 deletions
src/Simplex2.java
src/input.txt
+1
-2
1 addition, 2 deletions
src/input.txt
with
116 additions
and
10 deletions
src/Main.java
+
5
−
5
View file @
734a0c98
...
@@ -72,22 +72,22 @@ public class Main {
...
@@ -72,22 +72,22 @@ public class Main {
eq
.
printEq
(
line
);
eq
.
printEq
(
line
);
// Tableau initiale
// Tableau initiale
Simplex
spx
=
new
Simplex
(
line
+
1
,
line
+
3
,
widthMat
);
Simplex
2
spx
=
new
Simplex
2
(
widthMat
,
line
+
1
,
line
+
3
);
spx
.
create
MatEcart
(
eq
);
spx
.
create
Simplex
(
eq
);
spx
.
printSimplex
(
"Tableau"
);
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
// true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible
int
phase
=
spx
.
which_phase
();
int
phase
=
spx
.
which_phase
();
if
(
phase
!=
-
1
)
{
if
(
phase
!=
-
1
)
{
spx
.
tabAux
(
phase
);
/*
spx.tabAux(phase);
System.out.println("Tableau Auxiliaire:");
System.out.println("Tableau Auxiliaire:");
System
.
out
.
println
(
Arrays
.
deepToString
(
spx
.
getTabAux
()));
System.out.println(Arrays.deepToString(spx.getTabAux()));
*/
}
}
else
{
else
{
spx
.
pivot
();
spx
.
pivot
();
spx
.
printSimplex
(
"pivot"
);
spx
.
printSimplex
(
"pivot"
);
}
}
sc
.
close
();
sc
.
close
();
}
catch
(
FileNotFoundException
e
)
{
}
catch
(
FileNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
...
This diff is collapsed.
Click to expand it.
src/Simplex2.java
+
110
−
3
View file @
734a0c98
...
@@ -2,15 +2,122 @@ import java.util.ArrayList;
...
@@ -2,15 +2,122 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
public
class
Simplex2
{
public
class
Simplex2
{
private
int
nbLines
;
private
final
int
nbLines
;
private
int
x
;
private
int
x
;
private
int
y
;
private
int
y
;
private
ArrayList
<
ArrayList
<
Double
>>
simplex
;
private
ArrayList
<
ArrayList
<
Double
>>
simplex
;
public
Simplex2
(
int
nbLines
,
int
x
,
int
y
,
ArrayList
<
ArrayList
<
Double
>>
simplex
)
{
public
ArrayList
<
ArrayList
<
Double
>>
getSimplex
()
{
return
simplex
;
}
public
void
setSimplex
(
ArrayList
<
ArrayList
<
Double
>>
simplex
)
{
this
.
simplex
=
simplex
;
}
public
Simplex2
(
int
nbLines
,
int
x
,
int
y
)
{
this
.
nbLines
=
nbLines
;
this
.
nbLines
=
nbLines
;
this
.
x
=
x
;
this
.
x
=
x
;
this
.
y
=
y
;
this
.
y
=
y
;
this
.
simplex
=
new
ArrayList
<>();
this
.
simplex
=
new
ArrayList
<
ArrayList
<
Double
>>();
}
public
void
printSimplex
(
String
title
)
{
System
.
out
.
println
(
title
+
": "
);
for
(
ArrayList
<
Double
>
doubles
:
simplex
)
{
System
.
out
.
print
(
"["
);
for
(
Double
d
:
doubles
)
{
if
(
d
!=
null
)
{
System
.
out
.
printf
(
d
<
0.0
?
String
.
format
(
"%.2f "
,
d
)
:
String
.
format
(
" %.2f "
,
d
));
}
}
System
.
out
.
println
(
"]"
);
}
}
void
createSimplex
(
Equation
eq
)
{
int
nbContraintes
=
eq
.
getNbContraintes
();
for
(
int
i
=
0
;
i
<
x
;
i
++)
{
ArrayList
<
Double
>
tmp
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
y
;
j
++)
{
if
(
j
<
nbContraintes
)
tmp
.
add
(
eq
.
getMatAtId
(
i
,
j
));
else
tmp
.
add
(
j
-
nbContraintes
==
i
?
1.0
:
0.0
);
}
simplex
.
add
(
tmp
);
}
// Membre de droite
for
(
int
i
=
0
;
i
<
x
-
1
;
i
++)
simplex
.
get
(
i
).
set
(
y
-
1
,
eq
.
getRightVec
().
get
(
i
));
// Fonction obj
ArrayList
<
Double
>
tmp
=
(
ArrayList
<
Double
>)
eq
.
getFuncObj
();
for
(
int
i
=
0
;
i
<
y
-
2
;
i
++)
tmp
.
add
(
0.0
);
simplex
.
set
(
x
-
1
,
tmp
);
}
boolean
signe
(
Double
d
)
{
return
d
<
0
;
}
int
which_phase
()
{
int
res
=
-
1
;
int
id
=
0
;
for
(
ArrayList
<
Double
>
doubles
:
simplex
)
{
if
(
signe
(
doubles
.
get
(
doubles
.
size
()
-
1
)))
{
res
=
id
;
}
id
++;
}
return
res
;
}
private
int
getFirstNeg
()
{
for
(
Double
d
:
simplex
.
get
(
x
-
1
))
if
(
signe
(
d
))
return
simplex
.
get
(
x
-
1
).
indexOf
(
d
);
return
-
1
;
}
private
int
ligneSortante
(
int
y
)
{
int
id
=
0
;
int
i
=
0
;
double
tmp
=
simplex
.
get
(
id
).
get
(
this
.
y
-
1
)
/
simplex
.
get
(
id
).
get
(
y
);
for
(
ArrayList
<
Double
>
doubles
:
simplex
)
{
double
tmp_s
=
doubles
.
get
(
this
.
y
-
1
)
/
doubles
.
get
(
y
-
1
);
if
(
tmp_s
<
tmp
)
{
id
=
i
;
tmp
=
tmp_s
;
}
i
++;
}
return
id
;
}
void
pivot
()
{
int
firstNeg
=
getFirstNeg
();
if
(
firstNeg
==
-
1
)
return
;
boolean
has_neg
=
false
;
int
id
=
ligneSortante
(
firstNeg
);
double
pivot
=
simplex
.
get
(
id
).
get
(
firstNeg
);
for
(
Double
d
:
simplex
.
get
(
id
))
d
/=
pivot
;
for
(
ArrayList
<
Double
>
doubles
:
simplex
)
{
pivot
=
doubles
.
get
(
firstNeg
);
for
(
Double
d
:
doubles
)
{
if
(
doubles
.
indexOf
(
d
)
!=
id
)
{
d
-=
pivot
*
simplex
.
get
(
id
).
get
(
doubles
.
indexOf
(
d
));
}
}
}
for
(
Double
d
:
simplex
.
get
(
x
-
1
))
{
if
(
signe
(
d
))
{
has_neg
=
true
;
}
}
if
(
has_neg
)
pivot
();
}
}
}
}
This diff is collapsed.
Click to expand it.
src/input.txt
+
1
−
2
View file @
734a0c98
...
@@ -2,4 +2,3 @@ min;-8;-9;
...
@@ -2,4 +2,3 @@ min;-8;-9;
2;5;<=;12;
2;5;<=;12;
50;5;<=;150;
50;5;<=;150;
5;50;<=;100;
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