Skip to content
Snippets Groups Projects
Commit 039232ba authored by OUATTARA Sie's avatar OUATTARA Sie
Browse files

correction de la fonctionFractionnelle

parent 8d48fa47
No related branches found
No related tags found
1 merge request!2correction de la fonctionFractionnelle
No preview for this file type
No preview for this file type
......@@ -5,6 +5,7 @@ public class App {
Backpack backpack= new InstanceReader().read("src/sacTest");
backpack.sortByRatio();
backpack.solutionFractionnelle();
System.out.println("sac :" + backpack);
System.out.println("solution fractionnelle :" + backpack.getSfValuee());
}
}
......@@ -27,13 +27,21 @@ public class Backpack {
this.sortByRatio();
for(Loot loot : loots){
if(loot.getWeight() > this.capacity){
sfValuee += (loot.getValue() * loot.getWeight()) / (capacity - sfWeight);
if(loot.getWeight() > (capacity - sfWeight)){
System.out.println("value :"+loot.getValue());
System.out.println("value1 :"+loot.getWeight());
System.out.println("value2 :"+(capacity - sfWeight));
System.out.println("value1 :"+sfValuee);
sfValuee += (loot.getValue() * (capacity - sfWeight)) / loot.getWeight();
sfWeight += capacity - sfWeight;
System.out.println("frac :"+sfValuee);
System.out.println("frac :"+sfWeight);
}
else {
sfValuee += loot.getWeight();
else if (sfWeight < capacity){
sfValuee += loot.getValue();
sfWeight += loot.getWeight();
System.out.println("no frac :"+sfValuee);
System.out.println("no frac :"+sfWeight);
}
}
}
......
......@@ -5,7 +5,7 @@ public class Loot {
public Loot(int weight, int value) {
this.weight = weight;
this.value = value;
this.ratio = (float) weight/value;
this.ratio = (float) value/weight;
}
public String toString(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment