fix throw not exists paths
This commit is contained in:
@@ -39,6 +39,8 @@ public class TransitPath {
|
|||||||
} else {
|
} else {
|
||||||
fuel = refill(edges, entries.size()-1);
|
fuel = refill(edges, entries.size()-1);
|
||||||
}
|
}
|
||||||
|
if (fuel < 0)
|
||||||
|
throw new IllegalStateException("Is not exists path");
|
||||||
refillCount++;
|
refillCount++;
|
||||||
} else {
|
} else {
|
||||||
fuel -= fuelCost;
|
fuel -= fuelCost;
|
||||||
@@ -62,14 +64,14 @@ public class TransitPath {
|
|||||||
}
|
}
|
||||||
double remain = max != -1 ? Math.min(max, e.getRefill()) : e.getRefill();
|
double remain = max != -1 ? Math.min(max, e.getRefill()) : e.getRefill();
|
||||||
double fuelCost = e.getFuelCost(remain);
|
double fuelCost = e.getFuelCost(remain);
|
||||||
|
double fuel = updateFuelCost(edges, i+1, startIndex, remain-fuelCost);
|
||||||
|
if (fuel < 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this.fuelCost += fuelCost - ce.getFuelCost();
|
this.fuelCost += fuelCost - ce.getFuelCost();
|
||||||
ce.setFuelCost(fuelCost);
|
ce.setFuelCost(fuelCost);
|
||||||
ce.setRefill(remain);
|
ce.setRefill(remain);
|
||||||
remain = updateFuelCost(edges, i+1, startIndex, remain-fuelCost);
|
return fuel;
|
||||||
if (remain < 0){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return remain;
|
|
||||||
}
|
}
|
||||||
if (max == -1 || e.getMaxFuel() < max){
|
if (max == -1 || e.getMaxFuel() < max){
|
||||||
max = e.getMaxFuel();
|
max = e.getMaxFuel();
|
||||||
|
|||||||
@@ -186,6 +186,10 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
path = path.add(cEdge);
|
path = path.add(cEdge);
|
||||||
|
if (path.getMinFuel() > path.getMaxFuel()){
|
||||||
|
LOG.trace("Path inaccessible");
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!source.equals(target)){
|
if (!source.equals(target)){
|
||||||
addEdge(source, target, path);
|
addEdge(source, target, path);
|
||||||
}
|
}
|
||||||
@@ -235,6 +239,10 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
path = path.add(cEdge);
|
path = path.add(cEdge);
|
||||||
|
if (path.getMinFuel() > path.getMaxFuel()){
|
||||||
|
LOG.trace("Path inaccessible");
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!source.equals(target)){
|
if (!source.equals(target)){
|
||||||
addEdge(source, target, path);
|
addEdge(source, target, path);
|
||||||
}
|
}
|
||||||
@@ -430,7 +438,7 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
|||||||
int jumps = source.getEntry().getPlace().equals(target.getEntry().getPlace())? 0 : 1;
|
int jumps = source.getEntry().getPlace().equals(target.getEntry().getPlace())? 0 : 1;
|
||||||
int lands = 1; double fuel = fuelCost;
|
int lands = 1; double fuel = fuelCost;
|
||||||
if (path != null){
|
if (path != null){
|
||||||
jumps = path.size(); fuel = getFuelCost();
|
jumps = path.size()-1; fuel = getFuelCost();
|
||||||
lands += path.getRefillCount();
|
lands += path.getRefillCount();
|
||||||
}
|
}
|
||||||
double profit = getProfit();
|
double profit = getProfit();
|
||||||
|
|||||||
Reference in New Issue
Block a user