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
e8364d4e
Commit
e8364d4e
authored
2 years ago
by
thibault.capt
Browse files
Options
Downloads
Patches
Plain Diff
Création d'une classe Matrix.java pour gérer nos tableaux à deux dimensions
parent
92462af9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Matrix.java
+13
-3
13 additions, 3 deletions
src/Matrix.java
src/Simplex.java
+31
-29
31 additions, 29 deletions
src/Simplex.java
with
44 additions
and
32 deletions
src/Matrix.java
+
13
−
3
View file @
e8364d4e
...
@@ -36,7 +36,7 @@ public class Matrix {
...
@@ -36,7 +36,7 @@ public class Matrix {
this
.
data
=
new
double
[
x
][
y
];
this
.
data
=
new
double
[
x
][
y
];
}
}
public
void
matrixFill
(
int
x
,
int
y
,
double
[][]
tab
)
throws
Runtime
Exception
{
public
void
matrixFill
(
int
x
,
int
y
,
double
[][]
tab
)
throws
IndexOutOfBounds
Exception
{
for
(
int
i
=
0
;
i
<
x
;
i
++)
{
for
(
int
i
=
0
;
i
<
x
;
i
++)
{
for
(
int
j
=
0
;
j
<
y
;
j
++)
{
for
(
int
j
=
0
;
j
<
y
;
j
++)
{
this
.
data
[
i
][
j
]
=
tab
[
i
][
j
];
this
.
data
[
i
][
j
]
=
tab
[
i
][
j
];
...
@@ -44,12 +44,22 @@ public class Matrix {
...
@@ -44,12 +44,22 @@ public class Matrix {
}
}
}
}
public
void
matrixInitFromArray
(
double
[]
tab
)
throws
IndexOutOfBoundsException
{
int
id
=
0
;
for
(
int
i
=
0
;
i
<
x
;
i
++)
{
for
(
int
j
=
0
;
j
<
y
;
j
++)
{
this
.
data
[
i
][
j
]
=
tab
[
id
];
id
++;
}
}
}
public
void
matrixRealloc
(
int
x
,
int
y
)
{
public
void
matrixRealloc
(
int
x
,
int
y
)
{
double
[][]
tmp
=
this
.
data
;
double
[][]
tmp
=
this
.
data
;
this
.
data
=
new
double
[
x
][
y
];
matrixFill
(
x
,
y
,
tmp
);
this
.
x
=
x
;
this
.
x
=
x
;
this
.
y
=
y
;
this
.
y
=
y
;
this
.
data
=
new
double
[
x
][
y
];
matrixFill
(
x
,
y
,
tmp
);
}
}
public
void
matrixPrint
(
String
s
)
{
public
void
matrixPrint
(
String
s
)
{
...
...
This diff is collapsed.
Click to expand it.
src/Simplex.java
+
31
−
29
View file @
e8364d4e
...
@@ -3,14 +3,17 @@ import java.util.Arrays;
...
@@ -3,14 +3,17 @@ import java.util.Arrays;
public
class
Simplex
{
public
class
Simplex
{
private
final
Matrix
matEcart
;
private
final
Matrix
matEcart
;
private
final
Matrix
tabAux
;
private
final
Matrix
tabAux
;
private
final
int
nbLines
;
private
final
int
nbLines
;
private
final
int
x
;
private
final
int
y
;
public
double
[][]
getTabAux
()
{
public
double
[][]
getTabAux
()
{
return
tabAux
.
getDatas
();
return
tabAux
.
getDatas
();
}
}
public
Simplex
(
int
x
,
int
y
,
int
nbLines
)
{
public
Simplex
(
int
x
,
int
y
,
int
nbLines
)
{
this
.
x
=
x
;
this
.
y
=
y
;
this
.
matEcart
=
new
Matrix
(
x
,
y
);
this
.
matEcart
=
new
Matrix
(
x
,
y
);
this
.
nbLines
=
nbLines
;
this
.
nbLines
=
nbLines
;
this
.
tabAux
=
new
Matrix
(
x
+
nbLines
+
1
,
y
+
1
);
this
.
tabAux
=
new
Matrix
(
x
+
nbLines
+
1
,
y
+
1
);
...
@@ -19,8 +22,8 @@ public class Simplex {
...
@@ -19,8 +22,8 @@ public class Simplex {
void
createSimplex
(
Equation
eq
)
{
void
createSimplex
(
Equation
eq
)
{
int
nbContraintes
=
eq
.
getNbContraintes
();
int
nbContraintes
=
eq
.
getNbContraintes
();
// Matrice Amxn
// Matrice Amxn
for
(
int
i
=
0
;
i
<
this
.
matEcart
.
getX
()
;
i
++)
{
for
(
int
i
=
0
;
i
<
this
.
x
;
i
++)
{
for
(
int
j
=
0
;
j
<
this
.
matEcart
.
getY
()
;
j
++)
{
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
if
(
j
<
nbContraintes
)
{
if
(
j
<
nbContraintes
)
{
this
.
matEcart
.
setData
(
i
,
j
,
eq
.
getMatAtId
(
i
,
j
));
this
.
matEcart
.
setData
(
i
,
j
,
eq
.
getMatAtId
(
i
,
j
));
}
else
{
}
else
{
...
@@ -30,15 +33,15 @@ public class Simplex {
...
@@ -30,15 +33,15 @@ public class Simplex {
}
}
// Membre de droite
// Membre de droite
for
(
int
i
=
0
;
i
<=
this
.
matEcart
.
getX
()-
2
;
i
++)
for
(
int
i
=
0
;
i
<=
this
.
x
-
2
;
i
++)
this
.
matEcart
.
setData
(
i
,
this
.
matEcart
.
getY
()-
1
,
eq
.
getRightVec
().
get
(
i
));
this
.
matEcart
.
setData
(
i
,
this
.
y
-
1
,
eq
.
getRightVec
().
get
(
i
));
// Fonction obj
// Fonction obj
for
(
int
i
=
0
;
i
<
nbContraintes
;
i
++)
for
(
int
i
=
0
;
i
<
nbContraintes
;
i
++)
this
.
matEcart
.
setData
(
this
.
matEcart
.
getX
()
-
1
,
i
,
eq
.
getFuncObj
().
get
(
i
));
this
.
matEcart
.
setData
(
this
.
x
-
1
,
i
,
eq
.
getFuncObj
().
get
(
i
));
// overwrite la matrice en bas à droite qui est à 1
// overwrite la matrice en bas à droite qui est à 1
.
this
.
matEcart
.
setData
(
this
.
matEcart
.
getX
()
-
1
,
this
.
matEcart
.
getY
()
-
1
,
0.0
);
this
.
matEcart
.
setData
(
this
.
x
-
1
,
this
.
y
-
1
,
0.0
);
}
}
/**
/**
...
@@ -47,38 +50,37 @@ public class Simplex {
...
@@ -47,38 +50,37 @@ public class Simplex {
*/
*/
int
which_phase
(){
int
which_phase
(){
int
res
=
-
1
;
int
res
=
-
1
;
for
(
int
i
=
0
;
i
<
this
.
matEcart
.
getX
();
i
++)
{
for
(
int
i
=
0
;
i
<
this
.
x
;
i
++)
{
if
(
signe
(
this
.
matEcart
.
getData
(
i
,
this
.
matEcart
.
getY
()
-
1
)))
if
(
signe
(
this
.
matEcart
.
getData
(
i
,
this
.
y
-
1
)))
res
=
i
;
res
=
i
;
}
}
return
res
;
return
res
;
}
}
void
tabAux
(
int
line
)
{
void
tabAux
(
int
line
)
{
Double
[]
tabRes
=
new
Double
[
this
.
matEcart
.
getY
()
];
Double
[]
tabRes
=
new
Double
[
this
.
y
];
Arrays
.
fill
(
tabRes
,
0.0
);
Arrays
.
fill
(
tabRes
,
0.0
);
for
(
int
j
=
0
;
j
<
this
.
matEcart
.
getY
()
;
j
++)
{
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
if
(
this
.
matEcart
.
getData
(
line
,
j
)
!=
0.0
)
{
if
(
this
.
matEcart
.
getData
(
line
,
j
)
!=
0.0
)
{
double
res
=
this
.
matEcart
.
getData
(
line
,
j
)
*
-
1
;
double
res
=
this
.
matEcart
.
getData
(
line
,
j
)
*
-
1
;
this
.
matEcart
.
setData
(
line
,
j
,
res
);
this
.
matEcart
.
setData
(
line
,
j
,
res
);
}
}
for
(
int
i
=
0
;
i
<
this
.
matEcart
.
getX
()
-
1
;
i
++)
for
(
int
i
=
0
;
i
<
this
.
x
-
1
;
i
++)
tabRes
[
j
]
-=
this
.
matEcart
.
getData
(
i
,
j
);
tabRes
[
j
]
-=
this
.
matEcart
.
getData
(
i
,
j
);
}
}
for
(
int
i
=
0
;
i
<
this
.
matEcart
.
getX
()
+
nbLines
+
1
;
i
++)
{
for
(
int
i
=
0
;
i
<
this
.
x
+
nbLines
+
1
;
i
++)
{
for
(
int
j
=
0
;
j
<
this
.
matEcart
.
getY
()
+
1
;
j
++)
{
for
(
int
j
=
0
;
j
<
this
.
y
+
1
;
j
++)
{
if
(
i
<
this
.
matEcart
.
getX
()
&&
j
<
this
.
matEcart
.
getY
()
)
if
(
i
<
this
.
x
&&
j
<
this
.
y
)
this
.
tabAux
.
setData
(
i
,
j
,
this
.
matEcart
.
getData
(
i
,
j
));
this
.
tabAux
.
setData
(
i
,
j
,
this
.
matEcart
.
getData
(
i
,
j
));
else
if
(
i
>=
this
.
matEcart
.
getX
()
)
else
if
(
i
>=
this
.
x
)
this
.
tabAux
.
setData
(
i
,
j
,
this
.
matEcart
.
getData
(
i
-
5
,
j
));
this
.
tabAux
.
setData
(
i
,
j
,
this
.
matEcart
.
getData
(
i
-
5
,
j
));
else
if
(
j
==
this
.
matEcart
.
getY
()
)
else
if
(
j
==
this
.
y
)
this
.
tabAux
.
setData
(
i
,
j
,
tabRes
[
i
]);
this
.
tabAux
.
setData
(
i
,
j
,
tabRes
[
i
]);
}
}
}
}
}
}
int
getFirstNeg
()
{
int
getFirstNeg
()
{
for
(
int
j
=
0
;
j
<
this
.
matEcart
.
getY
()
;
j
++)
{
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
if
(
signe
(
this
.
matEcart
.
getData
(
this
.
matEcart
.
getX
()
-
1
,
j
)))
return
j
;
if
(
signe
(
this
.
matEcart
.
getData
(
this
.
x
-
1
,
j
)))
return
j
;
}
}
return
-
1
;
return
-
1
;
}
}
...
@@ -89,19 +91,19 @@ public class Simplex {
...
@@ -89,19 +91,19 @@ public class Simplex {
boolean
has_neg
=
false
;
boolean
has_neg
=
false
;
int
id
=
ligneSortante
(
firstNeg
);
int
id
=
ligneSortante
(
firstNeg
);
double
pivot
=
this
.
matEcart
.
getData
(
id
,
firstNeg
);
double
pivot
=
this
.
matEcart
.
getData
(
id
,
firstNeg
);
for
(
int
i
=
0
;
i
<
this
.
matEcart
.
getY
()
;
i
++)
{
for
(
int
i
=
0
;
i
<
this
.
y
;
i
++)
{
this
.
matEcart
.
setData
(
id
,
i
,
this
.
matEcart
.
getData
(
id
,
i
)
/
pivot
);
this
.
matEcart
.
setData
(
id
,
i
,
this
.
matEcart
.
getData
(
id
,
i
)
/
pivot
);
}
}
for
(
int
i
=
0
;
i
<
this
.
matEcart
.
getX
()
;
i
++)
{
for
(
int
i
=
0
;
i
<
this
.
x
;
i
++)
{
pivot
=
this
.
matEcart
.
getData
(
i
,
firstNeg
);
pivot
=
this
.
matEcart
.
getData
(
i
,
firstNeg
);
for
(
int
j
=
0
;
j
<
this
.
matEcart
.
getY
()
;
j
++)
{
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
{
if
(
i
!=
id
)
{
if
(
i
!=
id
)
{
this
.
matEcart
.
setData
(
i
,
j
,
this
.
matEcart
.
getData
(
i
,
j
)
-
pivot
*
this
.
matEcart
.
getData
(
id
,
j
));
this
.
matEcart
.
setData
(
i
,
j
,
this
.
matEcart
.
getData
(
i
,
j
)
-
pivot
*
this
.
matEcart
.
getData
(
id
,
j
));
}
}
}
}
}
}
for
(
int
j
=
0
;
j
<
this
.
matEcart
.
getY
()
;
j
++)
for
(
int
j
=
0
;
j
<
this
.
y
;
j
++)
if
(
signe
(
this
.
matEcart
.
getData
(
this
.
matEcart
.
getX
()
-
1
,
j
)))
{
if
(
signe
(
this
.
matEcart
.
getData
(
this
.
x
-
1
,
j
)))
{
has_neg
=
true
;
has_neg
=
true
;
}
}
if
(
has_neg
)
pivot
();
if
(
has_neg
)
pivot
();
...
@@ -110,9 +112,9 @@ public class Simplex {
...
@@ -110,9 +112,9 @@ public class Simplex {
int
ligneSortante
(
int
y
)
{
int
ligneSortante
(
int
y
)
{
int
id
=
0
;
int
id
=
0
;
double
tmp
=
this
.
matEcart
.
getData
(
id
,
this
.
matEcart
.
getY
()
-
1
)
/
this
.
matEcart
.
getData
(
id
,
y
);
double
tmp
=
this
.
matEcart
.
getData
(
id
,
this
.
y
-
1
)
/
this
.
matEcart
.
getData
(
id
,
y
);
for
(
int
i
=
1
;
i
<
this
.
matEcart
.
getX
()
-
1
;
i
++)
{
for
(
int
i
=
1
;
i
<
this
.
x
-
1
;
i
++)
{
double
tmp_s
=
this
.
matEcart
.
getData
(
i
,
this
.
matEcart
.
getY
()
-
1
)
/
this
.
matEcart
.
getData
(
i
,
y
);
double
tmp_s
=
this
.
matEcart
.
getData
(
i
,
this
.
y
-
1
)
/
this
.
matEcart
.
getData
(
i
,
y
);
if
(
tmp_s
<
tmp
)
{
if
(
tmp_s
<
tmp
)
{
id
=
i
;
id
=
i
;
tmp
=
tmp_s
;
tmp
=
tmp_s
;
...
...
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