Commit a1fe6e6b authored by rokka's avatar rokka

better naming

parent 721e4a6d
......@@ -3,14 +3,18 @@ public class WarenKiste {
public double width;
public double depth;
public double kisteDiagonal = (Math.pow(this.height + this.weight + this.depth, 2));
public double weight;
public double kisteDiagonal;
public WarenKiste(double height, double width, double depth, double weight) {
this.height = height;
this.width = width;
this.depth = depth;
this.weight = weight;
this.kisteDiagonal = (Math.pow(height + width + depth, 2));
}
}
......@@ -11,20 +11,20 @@ public class WarenRegalSystem {
}
public boolean sucheSegmentFuerKiste(WarenKiste kiste) {
int bestFittingSegmentIndex = -1;
double lastFitness = Integer.MAX_VALUE;
int bestSuitedSegmentIndex = -1;
double lastSuitablity = Integer.MAX_VALUE;
for (int i = 0; i < this.segmente.length; i++) {
double tmpFitness = kisteFitnessScore(kiste, segmente[i]);
if (tmpFitness >= 0 && tmpFitness < lastFitness ) {
lastFitness = tmpFitness;
bestFittingSegmentIndex = i;
double tmpSuitablity = segmentSuitablity(kiste, segmente[i]);
if (tmpSuitablity < lastSuitablity && tmpSuitablity >= 0) {
lastSuitablity = tmpSuitablity;
bestSuitedSegmentIndex = i;
}
}
try {
if (bestFittingSegmentIndex != -1) {
this.segmente[bestFittingSegmentIndex].kisteHinzufuegen(kiste);
if (bestSuitedSegmentIndex != -1) {
this.segmente[bestSuitedSegmentIndex].kisteHinzufuegen(kiste);
return true;
}
} catch (WarenSegment.AllSlotsInUseException exception) {
......@@ -34,10 +34,11 @@ public class WarenRegalSystem {
return false;
}
double kisteFitnessScore(WarenKiste kiste, WarenSegment warenSegment ){
double kisteWeightFitness = warenSegment.maxWeight - kiste.weight;
double kisteSizeFitness = (warenSegment.segmentSlotDiagonal - kiste.kisteDiagonal);
double segmentSuitablity(WarenKiste kiste, WarenSegment warenSegment ){
double segmentWeightSuitablity = warenSegment.maxWeight - kiste.weight;
double segmentSizeSuitablity = (warenSegment.segmentSlotDiagonal - kiste.kisteDiagonal);
double segmentSuitablity = segmentWeightSuitablity + segmentSizeSuitablity;
return (kisteWeightFitness >= 0 && kisteSizeFitness >= 0) ? kisteSizeFitness + kisteWeightFitness : -1;
return (segmentWeightSuitablity >= 0 && segmentSizeSuitablity >= 0) ? segmentSuitablity: -1;
}
}
\ No newline at end of file
public class WarenSegment {
class AllSlotsInUseException extends Exception{
class AllSlotsInUseException extends Exception {
AllSlotsInUseException(String message) {
super(message);
}
}
private AllSlotsInUseException allSlotsInUseException;
class SlotNotSuitableException extends Exception{
private class SlotNotSuitableException extends Exception {
SlotNotSuitableException(String message) {
super(message);
}
}
private SlotNotSuitableException toBig;
private SlotNotSuitableException toHeavy;
public WarenKiste[] segmentSlots;
public double maxHeight;
public double maxWidth;
public double maxDepth;
public double segmentSlotDiagonal = (Math.pow((maxHeight + maxWidth + maxDepth) / 3, 2));
public double maxWeight;
public WarenSegment(double maxHeight, double maxWidth, double maxDepth, double maxWeight) {
this.allSlotsInUseException = new AllSlotsInUseException("All slots are in use.");
this.toBig = new SlotNotSuitableException("Kiste size is to big for this segment.");
this.toHeavy = new SlotNotSuitableException("Kiste is to heavy for this segment.");
public double segmentSlotDiagonal;
public WarenSegment(double maxHeight, double maxWidth, double maxDepth, double maxWeight) {
this.segmentSlots = new WarenKiste[9];
this.maxHeight = maxHeight;
......@@ -41,19 +31,21 @@ public class WarenSegment {
this.maxDepth = maxDepth;
this.maxWeight = maxWeight;
this.segmentSlotDiagonal = (Math.pow((maxHeight + maxWidth + maxDepth) / 3, 2));
}
void kisteHinzufuegen(WarenKiste kiste) throws AllSlotsInUseException {
double kisteDiagonal = (Math.pow(kiste.height + kiste.weight + kiste.depth, 2));
double kisteDiagonal = (Math.pow(kiste.height + kiste.width + kiste.depth, 2));
try {
if (kiste.weight > this.maxWeight) {
throw this.toHeavy;
throw new SlotNotSuitableException("Kiste is to heavy for this segment.");
}
if (kisteDiagonal > this.segmentSlotDiagonal) {
throw this.toBig;
throw new SlotNotSuitableException("Kiste is to big for this segment.");
}
boolean allSlotsInUse = true;
......@@ -67,7 +59,7 @@ public class WarenSegment {
}
if (allSlotsInUse) {
throw this.allSlotsInUseException;
throw new AllSlotsInUseException("All slots are in use.");
}
} catch (SlotNotSuitableException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment