Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Branch-and-Bound
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
OUATTARA Sie
Branch-and-Bound
Commits
f62f4c98
Commit
f62f4c98
authored
4 months ago
by
GOUNOU Boubacar
Browse files
Options
Downloads
Patches
Plain Diff
Mise à jout des objets
parent
5400343c
No related branches found
No related tags found
1 merge request
!4
Dev1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
out/production/aroTP2/App.class
+0
-0
0 additions, 0 deletions
out/production/aroTP2/App.class
src/App.java
+2
-0
2 additions, 0 deletions
src/App.java
src/Backpack.java
+13
-0
13 additions, 0 deletions
src/Backpack.java
with
15 additions
and
0 deletions
out/production/aroTP2/App.class
+
0
−
0
View file @
f62f4c98
No preview for this file type
This diff is collapsed.
Click to expand it.
src/App.java
+
2
−
0
View file @
f62f4c98
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
public
class
App
{
public
class
App
{
...
@@ -5,5 +6,6 @@ public class App {
...
@@ -5,5 +6,6 @@ public class App {
Backpack
backpack
=
new
InstanceReader
().
read
(
"src/sac4"
);
Backpack
backpack
=
new
InstanceReader
().
read
(
"src/sac4"
);
backpack
.
solve
();
backpack
.
solve
();
System
.
out
.
println
(
"meilleur solution :"
+
backpack
.
getBestValue
());
System
.
out
.
println
(
"meilleur solution :"
+
backpack
.
getBestValue
());
System
.
out
.
println
(
"meilleur solution :"
+
Arrays
.
toString
(
backpack
.
getBestSolution
()));
}
}
}
}
This diff is collapsed.
Click to expand it.
src/Backpack.java
+
13
−
0
View file @
f62f4c98
...
@@ -7,16 +7,22 @@ public class Backpack {
...
@@ -7,16 +7,22 @@ public class Backpack {
private
int
bestValue
=
0
;
private
int
bestValue
=
0
;
private
int
currentWeight
=
0
;
private
int
currentWeight
=
0
;
private
int
currentValue
=
0
;
private
int
currentValue
=
0
;
private
boolean
[]
currentSolution
;
private
boolean
[]
bestSolution
;
public
Backpack
(
int
capacity
,
List
<
Loot
>
loots
)
{
public
Backpack
(
int
capacity
,
List
<
Loot
>
loots
)
{
this
.
capacity
=
capacity
;
this
.
capacity
=
capacity
;
this
.
loots
=
loots
;
this
.
loots
=
loots
;
this
.
currentSolution
=
new
boolean
[
loots
.
size
()];
this
.
bestSolution
=
new
boolean
[
loots
.
size
()];
}
}
public
void
solve
()
{
public
void
solve
()
{
this
.
sortByRatio
();
this
.
sortByRatio
();
explore_from
(
0
);
explore_from
(
0
);
System
.
out
.
println
(
"La valeur optimale est : "
+
bestValue
);
System
.
out
.
println
(
"La valeur optimale est : "
+
bestValue
);
System
.
out
.
println
(
"Objets inclus dans la solution optimale : "
+
bestSolution
);
}
}
public
String
toString
(){
public
String
toString
(){
...
@@ -57,6 +63,7 @@ public class Backpack {
...
@@ -57,6 +63,7 @@ public class Backpack {
if
(
index
>=
loots
.
size
())
{
if
(
index
>=
loots
.
size
())
{
if
(
currentValue
>
bestValue
)
{
if
(
currentValue
>
bestValue
)
{
bestValue
=
currentValue
;
bestValue
=
currentValue
;
System
.
arraycopy
(
currentSolution
,
0
,
bestSolution
,
0
,
loots
.
size
());
}
}
return
;
return
;
}
}
...
@@ -75,9 +82,11 @@ public class Backpack {
...
@@ -75,9 +82,11 @@ public class Backpack {
if
(
currentWeight
+
currentLoot
.
getWeight
()
<=
capacity
)
{
if
(
currentWeight
+
currentLoot
.
getWeight
()
<=
capacity
)
{
currentWeight
+=
currentLoot
.
getWeight
();
currentWeight
+=
currentLoot
.
getWeight
();
currentValue
+=
currentLoot
.
getValue
();
currentValue
+=
currentLoot
.
getValue
();
currentSolution
[
index
]
=
true
;
explore_from
(
index
+
1
);
explore_from
(
index
+
1
);
currentWeight
-=
currentLoot
.
getWeight
();
currentWeight
-=
currentLoot
.
getWeight
();
currentValue
-=
currentLoot
.
getValue
();
currentValue
-=
currentLoot
.
getValue
();
currentSolution
[
index
]
=
false
;
}
}
// on explore sans l'objet
// on explore sans l'objet
...
@@ -87,4 +96,8 @@ public class Backpack {
...
@@ -87,4 +96,8 @@ public class Backpack {
public
int
getBestValue
()
{
public
int
getBestValue
()
{
return
bestValue
;
return
bestValue
;
}
}
public
boolean
[]
getBestSolution
()
{
return
bestSolution
;
}
}
}
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