-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractMKP.java
More file actions
76 lines (64 loc) · 1.85 KB
/
AbstractMKP.java
File metadata and controls
76 lines (64 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package ads1ss13.pa;
import java.util.ArrayList;
/**
* Abstrakte Klasse zum Berechnen der Beladung des Rucksacks mittels Branch-and-Bound.
*
* <p>
* <b>WICHTIG:</b> Nehmen Sie keine Änderungen in dieser Klasse vor. Bei
* der Abgabe werden diese Änderungen verworfen und es könnte dadurch
* passieren, dass Ihr Programm somit nicht mehr korrekt funktioniert.
* </p>
*/
public abstract class AbstractMKP implements Runnable {
/** Die bisher beste Lösung */
private BnBSolution sol;
/**
* Diese Methode setzt einen neue (beste) Lösung.
*
* <p>
* <strong>ACHTUNG:</strong> die Lösung wird nur übernommen wenn
* <code>newLowerBound</code> höher ist als {@link #lowerBound}.
* </p>
*
* @param newLowerBound
* neue untere Schranke
* @param newSolution
* neue beste Lösung
* @return Wahr wenn die Lösung übernommen wurde.
*/
final public synchronized boolean setSolution(int newLowerBound, ArrayList<Item> newSolution) {
if (sol == null || newLowerBound > sol.getLowerBound()) {
sol = new BnBSolution(newLowerBound, newSolution);
return true;
}
return false;
}
/**
* Gibt die bisher beste gefundene Lösung zurück.
*
* @return Die bisher beste gefundene Lösung.
*/
final public BnBSolution getSolution() {
return sol;
}
public final class BnBSolution {
private int lowerBound = Integer.MAX_VALUE;
private ArrayList<Item> bestSolution;
public BnBSolution(int newLowerBound, ArrayList<Item> newSolution) {
lowerBound = newLowerBound;
bestSolution = newSolution;
}
/**
* @return Die untere Schranke
*/
public int getLowerBound() {
return lowerBound;
}
/**
* @return Die Items der bisher besten Lösung
*/
public ArrayList<Item> getBestSolution() {
return bestSolution;
}
}
}