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
852b70aa
Commit
852b70aa
authored
2 years ago
by
thibault.capt
Browse files
Options
Downloads
Patches
Plain Diff
finish part 1
parent
15d74d76
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Equation.java
+70
-21
70 additions, 21 deletions
src/Equation.java
src/Main.java
+13
-12
13 additions, 12 deletions
src/Main.java
with
83 additions
and
33 deletions
src/Equation.java
+
70
−
21
View file @
852b70aa
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
public
class
Equation
{
public
class
Equation
{
...
@@ -54,6 +53,10 @@ public class Equation {
...
@@ -54,6 +53,10 @@ public class Equation {
return
mat
;
return
mat
;
}
}
public
Double
getMatAtId
(
int
w
,
int
h
)
{
return
mat
[
w
][
h
];
}
public
void
setMat
(
Double
n
,
int
w
,
int
h
)
{
public
void
setMat
(
Double
n
,
int
w
,
int
h
)
{
this
.
mat
[
w
][
h
]
=
n
;
this
.
mat
[
w
][
h
]
=
n
;
}
}
...
@@ -81,48 +84,85 @@ public class Equation {
...
@@ -81,48 +84,85 @@ public class Equation {
}
}
/**
/**
* Créer le vecteurs éléments de droite et la matrice Amxn
* Créer le vecteurs éléments de droite et la matrice Amxn
quand le sens est à min
* @param elements
* @param elements
* @param line
* @param line
*/
*/
public
void
createEq
(
String
[]
elements
,
int
line
)
{
public
void
createMinEq
(
String
[]
elements
,
int
line
)
{
// Vecteur de droite
try
{
addInRightVec
(
elements
);
// vecteur de droite
setRightVec
(
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
// Matrice
// Matrice
addInMat
(
elements
,
line
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
setMat
(
Double
.
parseDouble
(
elements
[
i
]),
line
,
i
);
}
}
/**
* Ajouter dans le vecteur de droite
* @param elements
*/
public
void
addInRightVec
(
String
[]
elements
){
try
{
setRightVec
(
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
}
catch
(
NumberFormatException
ex
)
{
}
catch
(
NumberFormatException
ex
)
{
ex
.
printStackTrace
();
ex
.
printStackTrace
();
}
}
}
}
/**
/**
*
Ajouter dans la matrice
*
Créer le vecteurs éléments de droite et la matrice Amxn quand le sens est à max
* @param elements
* @param elements
* @param line
* @param line
*/
*/
public
void
addInMat
(
String
[]
elements
,
int
line
)
{
public
int
createMaxEq
(
String
[]
elements
,
int
line
)
{
try
{
try
{
// vecteur de droite
switch
(
elements
[
5
])
{
case
"="
:
// Si ax=b => ax <= b; ax >= b
// Vecteur de droite
setRightVec
(
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
setRightVec
(
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
// Matrice
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
setMat
(
Double
.
parseDouble
(
elements
[
i
]),
line
,
i
);
setMat
(
Double
.
parseDouble
(
elements
[
i
]),
line
,
i
);
setMat
(
Double
.
parseDouble
(
elements
[
i
]),
line
+
1
,
i
);
}
}
// On rajoute une ligne
line
+=
1
;
break
;
case
">="
:
// Vecteur de droite
setRightVec
(-
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
// Matrice
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
setMat
(-
Double
.
parseDouble
(
elements
[
i
]),
line
,
i
);
}
break
;
case
"<="
:
// Vecteur de droite
setRightVec
(
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
// Matrice
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
setMat
(
Double
.
parseDouble
(
elements
[
i
]),
line
,
i
);
}
break
;
}
}
catch
(
NumberFormatException
ex
)
{
}
catch
(
NumberFormatException
ex
)
{
ex
.
printStackTrace
();
ex
.
printStackTrace
();
}
}
return
line
;
}
/**
* Ajouter dans le vecteur de droite
* @param elements
*/
public
void
addInRightVec
(
String
[]
elements
){
}
}
/**
/**
* Print les vecteurs et la matrice
* Print les vecteurs et la matrice
*/
*/
public
void
printEq
(){
public
void
printEq
(
int
width
){
// Sens
// Sens
System
.
out
.
println
(
"Sens: "
+
getSens
());
System
.
out
.
println
(
"Sens: "
+
getSens
());
...
@@ -132,7 +172,16 @@ public class Equation {
...
@@ -132,7 +172,16 @@ public class Equation {
// Vecteur membre de droite
// Vecteur membre de droite
System
.
out
.
println
(
"Vecteur membre de droite: "
+
getRightVec
());
System
.
out
.
println
(
"Vecteur membre de droite: "
+
getRightVec
());
System
.
out
.
println
(
"Matrice Amxn:"
);
// Matrice Amxn
// Matrice Amxn
System
.
out
.
println
(
"Matrice Amxn: "
+
Arrays
.
deepToString
(
getMat
()));
for
(
int
i
=
0
;
i
<
width
;
i
++)
{
for
(
int
j
=
0
;
j
<
5
;
j
++)
{
if
(
getMatAtId
(
i
,
j
)
<
0
)
System
.
out
.
print
(
getMatAtId
(
i
,
j
)
+
" "
);
else
System
.
out
.
print
(
" "
+
getMatAtId
(
i
,
j
)
+
" "
);
}
System
.
out
.
println
();
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/Main.java
+
13
−
12
View file @
852b70aa
...
@@ -18,7 +18,7 @@ public class Main {
...
@@ -18,7 +18,7 @@ public class Main {
String
[]
elements
;
String
[]
elements
;
int
widthMat
=
nbLines
(
sc
);
int
widthMat
=
nbLines
(
sc
);
sc
=
new
Scanner
(
f
);
// remettre le scanner à la première ligne
sc
=
new
Scanner
(
f
);
// remettre le scanner à la première ligne
Equation
eq
=
new
Equation
(
widthMat
);
Equation
eq
=
new
Equation
(
widthMat
*
2
);
// ajout de ligne supp si sens: max et = donc + 1 ligne
int
line
=
0
;
int
line
=
0
;
// Max / Min + function obj
// Max / Min + function obj
...
@@ -26,21 +26,22 @@ public class Main {
...
@@ -26,21 +26,22 @@ public class Main {
elements
=
firstLine
.
split
(
";"
);
elements
=
firstLine
.
split
(
";"
);
eq
.
setFirstLine
(
elements
);
eq
.
setFirstLine
(
elements
);
if
(
eq
.
getSens
().
equals
(
"min"
))
{
// S.C.
// S.C.
while
(
sc
.
hasNextLine
())
{
while
(
sc
.
hasNextLine
())
{
String
tmp
=
sc
.
nextLine
();
String
tmp
=
sc
.
nextLine
();
elements
=
tmp
.
split
(
";"
);
elements
=
tmp
.
split
(
";"
);
eq
.
createEq
(
elements
,
line
);
line
++;
if
(
eq
.
getSens
().
equals
(
"min"
))
{
}
eq
.
createMinEq
(
elements
,
line
);
}
else
{
}
else
{
// TODO reverse eq
line
=
eq
.
createMaxEq
(
elements
,
line
);
System
.
out
.
println
(
"Reverse eq"
);
}
line
++;
}
}
// Print
// Print
eq
.
printEq
();
eq
.
printEq
(
line
);
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.
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