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
78898ff4
Commit
78898ff4
authored
2 years ago
by
thibault.capt
Browse files
Options
Downloads
Patches
Plain Diff
last update
parent
b4554495
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
+30
-10
30 additions, 10 deletions
src/Equation.java
src/Main.java
+13
-1
13 additions, 1 deletion
src/Main.java
with
43 additions
and
11 deletions
src/Equation.java
+
30
−
10
View file @
78898ff4
...
...
@@ -4,6 +4,7 @@ import java.util.List;
public
class
Equation
{
private
String
sens
;
private
int
nbContraintes
;
private
final
List
<
Double
>
funcObj
;
private
final
List
<
Double
>
rightVec
;
private
final
Double
[][]
mat
;
...
...
@@ -37,6 +38,19 @@ public class Equation {
}
}
public
int
getNbContraintes
()
{
if
(
this
.
nbContraintes
!=
-
1
)
return
this
.
nbContraintes
;
else
{
System
.
err
.
println
(
"Une erreur a été détectée"
);
return
-
1
;
}
}
public
void
setNbContraintes
(
int
nbContraintes
)
{
this
.
nbContraintes
=
nbContraintes
;
}
public
List
<
Double
>
getFuncObj
()
{
return
funcObj
;
}
...
...
@@ -61,11 +75,17 @@ public class Equation {
this
.
mat
[
w
][
h
]
=
n
;
}
public
Equation
(
int
width
)
{
/**
* Constructeur
* @param w hauteur de la matrice
* @param h largeur de la matrice
*/
public
Equation
(
int
w
,
int
h
)
{
this
.
sens
=
null
;
this
.
funcObj
=
new
ArrayList
<>();
this
.
rightVec
=
new
ArrayList
<>();
mat
=
new
Double
[
width
][
5
];
this
.
nbContraintes
=
h
;
mat
=
new
Double
[
w
][
h
];
}
/**
...
...
@@ -99,7 +119,7 @@ public class Equation {
public
int
createEq
(
String
[]
elements
,
int
line
)
{
try
{
// vecteur de droite
switch
(
elements
[
5
])
{
switch
(
elements
[
getNbContraintes
()
])
{
case
"="
:
// Si ax=b => ax <= b; ax >= b
double
res
=
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]);
// Vecteur de droite
...
...
@@ -110,7 +130,7 @@ public class Equation {
else
setRightVec
(-
res
);
// Matrice
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
for
(
int
i
=
0
;
i
<
getNbContraintes
()
;
i
++)
{
double
tmp
=
Double
.
parseDouble
(
elements
[
i
]);
setMat
(
tmp
,
line
,
i
);
// Si 0.0, ne pas écrire -0.0
...
...
@@ -125,7 +145,7 @@ public class Equation {
setRightVec
(-
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
// Matrice
for
(
int
i
=
0
;
i
<
5
;
i
++)
for
(
int
i
=
0
;
i
<
getNbContraintes
()
;
i
++)
setMat
(-
Double
.
parseDouble
(
elements
[
i
]),
line
,
i
);
break
;
case
"<="
:
...
...
@@ -133,7 +153,7 @@ public class Equation {
setRightVec
(
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
// Matrice
for
(
int
i
=
0
;
i
<
5
;
i
++)
for
(
int
i
=
0
;
i
<
getNbContraintes
()
;
i
++)
setMat
(
Double
.
parseDouble
(
elements
[
i
]),
line
,
i
);
break
;
default
:
...
...
@@ -149,7 +169,7 @@ public class Equation {
/**
* Print les vecteurs et la matrice
*/
public
void
printEq
(
int
w
idth
)
{
public
void
printEq
(
int
w
)
{
// Sens
System
.
out
.
println
(
"Sens: "
+
getSens
());
...
...
@@ -161,8 +181,8 @@ public class Equation {
System
.
out
.
println
(
"Matrice Amxn:"
);
// Matrice Amxn
for
(
int
i
=
0
;
i
<
w
idth
;
i
++)
{
for
(
int
j
=
0
;
j
<
5
;
j
++)
{
for
(
int
i
=
0
;
i
<
w
;
i
++)
{
for
(
int
j
=
0
;
j
<
getNbContraintes
()
;
j
++)
{
if
(
getMatAtId
(
i
,
j
)
<
0.0
)
System
.
out
.
print
(
getMatAtId
(
i
,
j
)
+
" "
);
else
...
...
This diff is collapsed.
Click to expand it.
src/Main.java
+
13
−
1
View file @
78898ff4
...
...
@@ -18,6 +18,16 @@ public class Main {
}
return
count
-
1
;
// A cause de la premiere ligne
}
/**
* Compter le nombre d'inéquations S.C
* @param sc scanner
* @return le nombre d'inéquations S.C
*/
private
static
Integer
nbContraintes
(
Scanner
sc
)
{
String
firstLine
=
sc
.
nextLine
();
String
[]
elements
=
firstLine
.
split
(
";"
);
return
elements
.
length
-
1
;
// Enlever le sens de la fonction
}
/**
* Fonction main
...
...
@@ -31,8 +41,10 @@ public class Main {
String
[]
elements
;
int
widthMat
=
nbLines
(
sc
);
sc
=
new
Scanner
(
f
);
// remettre le scanner à la première ligne
Equation
eq
=
new
Equation
(
widthMat
*
2
);
// lignes supp au cas où, il y a des "="
int
contraintes
=
nbContraintes
(
sc
);
sc
=
new
Scanner
(
f
);
// remettre le scanner à la première ligne
int
line
=
0
;
Equation
eq
=
new
Equation
(
widthMat
*
2
,
contraintes
);
// lignes supp au cas où, il y a des "="
// Max / Min + function obj
String
firstLine
=
sc
.
nextLine
();
...
...
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