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
145e68d3
Commit
145e68d3
authored
2 years ago
by
thibault.capt
Browse files
Options
Downloads
Patches
Plain Diff
manque reverse eq
parent
e89b2266
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
log.txt
+1
-0
1 addition, 0 deletions
log.txt
src/Equation.java
+88
-24
88 additions, 24 deletions
src/Equation.java
src/Main.java
+25
-31
25 additions, 31 deletions
src/Main.java
with
114 additions
and
55 deletions
log.txt
0 → 100644
+
1
−
0
View file @
145e68d3
2022/10/17 15:08:50 Micro started
This diff is collapsed.
Click to expand it.
src/Equation.java
+
88
−
24
View file @
145e68d3
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
Equation
{
private
String
_sens
;
private
String
_funcObj
;
private
final
ArrayList
<
String
>
_sc
;
private
String
sens
;
private
final
List
<
Double
>
funcObj
;
private
final
List
<
Double
>
rightVec
;
private
final
Double
[][]
mat
;
/**
* getter sens
* @return min | max | null
*/
public
String
getSens
()
{
return
_
sens
;
return
sens
;
}
public
void
setSens
(
String
_sens
)
{
this
.
_sens
=
_sens
;
/**
* Setter sens
* @param sens max | min
*/
public
void
setSens
(
String
sens
)
{
switch
(
sens
)
{
case
"min"
,
"max"
->
this
.
sens
=
sens
;
default
->
{
this
.
sens
=
null
;
System
.
err
.
println
(
"Le sens ne peut que être min ou max"
);
System
.
exit
(
1
);
}
}
}
public
List
<
Double
>
getFuncObj
()
{
return
funcObj
;
}
public
String
getFuncObj
()
{
return
_funcObj
;
public
void
setFuncObj
(
double
d
)
{
this
.
funcObj
.
add
(
d
);
}
public
List
<
Double
>
getRightVec
()
{
return
rightVec
;
}
public
void
set
FuncObj
(
String
funcObj
)
{
this
.
_funcObj
=
funcObj
;
public
void
set
RightVec
(
double
d
)
{
this
.
rightVec
.
add
(
d
)
;
}
public
ArrayList
<
String
>
get
Sc
()
{
return
_sc
;
public
Double
[][]
get
Mat
()
{
return
mat
;
}
public
void
setSc
(
String
s
)
{
this
.
_sc
.
add
(
s
);
public
void
setMat
(
Double
n
,
int
w
,
int
h
)
{
this
.
mat
[
w
][
h
]
=
n
;
}
public
Equation
(
int
width
)
{
this
.
sens
=
null
;
this
.
funcObj
=
new
ArrayList
<>();
this
.
rightVec
=
new
ArrayList
<>();
mat
=
new
Double
[
width
][
5
];
}
public
void
setFirstLine
(
String
[]
elements
)
{
try
{
setSens
(
elements
[
0
]);
for
(
int
i
=
1
;
i
<
elements
.
length
;
i
++){
setFuncObj
(
Double
.
parseDouble
(
elements
[
i
]));
}
}
catch
(
NumberFormatException
ex
)
{
ex
.
printStackTrace
();
}
}
public
Equation
()
{
setSens
(
null
);
setFuncObj
(
null
);
this
.
_sc
=
new
ArrayList
<>();
public
void
createEq
(
String
[]
elements
,
int
line
)
{
addInRightVec
(
elements
);
addInMat
(
elements
,
line
);
}
public
void
addInRightVec
(
String
[]
elements
){
try
{
setRightVec
(
Double
.
parseDouble
(
elements
[
elements
.
length
-
1
]));
}
catch
(
NumberFormatException
ex
)
{
ex
.
printStackTrace
();
}
}
public
void
addInMat
(
String
[]
elements
,
int
line
)
{
try
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
setMat
(
Double
.
parseDouble
(
elements
[
i
]),
line
,
i
);
}
}
catch
(
NumberFormatException
ex
)
{
ex
.
printStackTrace
();
}
}
public
void
printEq
(){
// Sens
System
.
out
.
println
(
"Sens: "
+
getSens
());
System
.
out
.
println
(
"Fonction objective: "
+
getFuncObj
());
System
.
out
.
println
(
"S.C.:"
);
for
(
String
s:
getSc
())
{
System
.
out
.
println
(
s
);
}
// Fonction obj
System
.
out
.
println
(
"Fonction obj: "
+
getFuncObj
());
// Vecteur membre de droite
System
.
out
.
println
(
"Vecteur membre de droite: "
+
getRightVec
());
// Matrice Amxn
System
.
out
.
println
(
"Matrice Amxn: "
+
Arrays
.
deepToString
(
getMat
()));
}
}
This diff is collapsed.
Click to expand it.
src/Main.java
+
25
−
31
View file @
145e68d3
...
...
@@ -3,49 +3,43 @@ import java.io.FileNotFoundException;
import
java.util.Scanner
;
public
class
Main
{
private
static
void
getFirstLine
(
Equation
eq
,
String
[]
elements
)
{
// Première ligne différente
eq
.
setSens
(
elements
[
0
]);
StringBuilder
funcObj
=
new
StringBuilder
();
for
(
int
i
=
1
;
i
<
elements
.
length
;
i
++)
if
(
i
==
elements
.
length
-
1
)
funcObj
.
append
(
elements
[
i
]);
else
funcObj
.
append
(
elements
[
i
]).
append
(
", "
);
eq
.
setFuncObj
(
String
.
valueOf
(
funcObj
));
}
private
static
void
newSC
(
Equation
eq
,
String
[]
elements
)
{
StringBuilder
str
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
elements
.
length
;
i
++
)
{
if
(
i
==
elements
.
length
-
1
)
str
.
append
(
elements
[
i
]);
else
str
.
append
(
elements
[
i
]).
append
(
", "
);
private
static
Integer
nbLines
(
Scanner
sc
)
{
int
count
=
0
;
while
(
sc
.
hasNextLine
())
{
count
++;
sc
.
nextLine
();
}
eq
.
setSc
(
String
.
valueOf
(
str
));
return
count
-
1
;
// A cause de la premiere ligne
}
public
static
void
main
(
String
[]
args
)
{
try
{
File
f
=
new
File
(
"src/input.txt"
);
Scanner
sc
=
new
Scanner
(
f
);
String
[]
elements
;
Equation
eq
=
new
Equation
();
int
widthMat
=
nbLines
(
sc
);
sc
=
new
Scanner
(
f
);
// remettre le scanner à la première ligne
Equation
eq
=
new
Equation
(
widthMat
);
int
line
=
0
;
//
Première ligne différente
//
Max / Min + function obj
String
firstLine
=
sc
.
nextLine
();
elements
=
firstLine
.
split
(
";"
);
g
etFirstLine
(
eq
,
elements
);
eq
.
s
etFirstLine
(
elements
);
// Le reste
if
(
eq
.
getSens
().
equals
(
"min"
))
{
// S.C.
while
(
sc
.
hasNextLine
())
{
String
tmp
=
sc
.
nextLine
();
elements
=
tmp
.
split
(
";"
);
newSC
(
eq
,
elements
);
eq
.
createEq
(
elements
,
line
);
line
++;
}
}
else
{
// TODO reverse eq
System
.
out
.
println
(
"Reverse eq"
);
}
// Print
eq
.
printEq
();
sc
.
close
();
}
catch
(
FileNotFoundException
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