refill fuel tank to optimal fuel
This commit is contained in:
@@ -52,7 +52,7 @@ public class CCrawler<T extends Connectable<T>> extends Crawler<T> {
|
||||
double nextLimit;
|
||||
if (cEdge.isRefill()) {
|
||||
LOG.trace("Refill");
|
||||
nextLimit = getShip().getTank() - cEdge.getFuelCost();
|
||||
nextLimit = cEdge.getRefill() - cEdge.getFuelCost();
|
||||
} else {
|
||||
nextLimit = getProfile().withRefill() ? cEntry.getFuel() - cEdge.getFuelCost() : getShip().getTank();
|
||||
}
|
||||
@@ -91,10 +91,9 @@ public class CCrawler<T extends Connectable<T>> extends Crawler<T> {
|
||||
double distance = source.getDistance(edge.target.getEntry());
|
||||
double fuelCost = getShip().getFuelCost(fuel, distance);
|
||||
double nextLimit = getProfile().withRefill() ? fuel - fuelCost : getShip().getTank();
|
||||
boolean refill = nextLimit < 0 && source.canRefill();
|
||||
if (refill) {
|
||||
refill = true;
|
||||
fuelCost = getShip().getFuelCost(distance);
|
||||
double refill = nextLimit < 0 && source.canRefill() ? getShip().getRoundMaxFuel(distance) : 0;
|
||||
if (refill > 0) {
|
||||
fuelCost = getShip().getFuelCost(refill, distance);
|
||||
}
|
||||
ConnectibleEdge<T> cEdge = new ConnectibleEdge<>(edge.getSource(), edge.getTarget());
|
||||
cEdge.setRefill(refill);
|
||||
|
||||
@@ -3,7 +3,7 @@ package ru.trader.analysis.graph;
|
||||
import ru.trader.graph.Connectable;
|
||||
|
||||
public class ConnectibleEdge<T extends Connectable<T>> extends Edge<T> {
|
||||
protected boolean refill;
|
||||
protected double refill;
|
||||
protected double fuelCost;
|
||||
|
||||
public ConnectibleEdge(Vertex<T> source, Vertex<T> target) {
|
||||
@@ -11,10 +11,14 @@ public class ConnectibleEdge<T extends Connectable<T>> extends Edge<T> {
|
||||
}
|
||||
|
||||
public boolean isRefill() {
|
||||
return refill != 0;
|
||||
}
|
||||
|
||||
public double getRefill() {
|
||||
return refill;
|
||||
}
|
||||
|
||||
protected void setRefill(boolean refill) {
|
||||
public void setRefill(double refill) {
|
||||
this.refill = refill;
|
||||
}
|
||||
|
||||
@@ -36,7 +40,7 @@ public class ConnectibleEdge<T extends Connectable<T>> extends Edge<T> {
|
||||
@Override
|
||||
public String toString() {
|
||||
return source.getEntry().toString() + " - "+ weight
|
||||
+ (refill ? "R" : "")
|
||||
+ (isRefill() ? "R" : "")
|
||||
+" -> " + target.getEntry().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +53,13 @@ public class ConnectibleGraph<T extends Connectable<T>> extends AbstractGraph<T>
|
||||
|
||||
@Override
|
||||
public boolean test(Double distance) {
|
||||
return distance <= getShip().getJumpRange(limit) || (profile.withRefill() && distance <= getShip().getJumpRange() && source.canRefill());
|
||||
return distance <= getShip().getJumpRange(limit) || (profile.withRefill() && distance <= getShip().getMaxJumpRange() && source.canRefill());
|
||||
}
|
||||
}
|
||||
|
||||
protected class ConnectibleGraphBuilder extends GraphBuilder {
|
||||
private final DistanceFilter distanceFilter;
|
||||
protected boolean refill;
|
||||
protected double refill;
|
||||
protected double fuelCost;
|
||||
|
||||
protected ConnectibleGraphBuilder(Vertex<T> vertex, Collection<T> set, int deep, double limit) {
|
||||
@@ -76,13 +76,13 @@ public class ConnectibleGraph<T extends Connectable<T>> extends AbstractGraph<T>
|
||||
}
|
||||
fuelCost = getShip().getFuelCost(limit, distance);
|
||||
double nextLimit = profile.withRefill() ? limit - fuelCost : getShip().getTank();
|
||||
if (nextLimit < 0) {
|
||||
if (nextLimit < 0 && vertex.getEntry().canRefill()) {
|
||||
LOG.trace("Refill");
|
||||
refill = true;
|
||||
fuelCost = getShip().getFuelCost(distance);
|
||||
nextLimit = getShip().getTank() - fuelCost;
|
||||
refill = getShip().getRoundMaxFuel(distance);
|
||||
fuelCost = getShip().getFuelCost(refill, distance);
|
||||
nextLimit = refill - fuelCost;
|
||||
} else {
|
||||
refill = false;
|
||||
refill = 0;
|
||||
}
|
||||
return nextLimit;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package ru.trader.core;
|
||||
|
||||
public class Ship {
|
||||
private final static int REFILL_FUEL_STEP = 10;
|
||||
|
||||
private int cargo;
|
||||
private Engine engine;
|
||||
private double tank;
|
||||
@@ -69,13 +71,36 @@ public class Ship {
|
||||
|
||||
//Laden fuel cost
|
||||
public double getFuelCost(double distance){
|
||||
return engine.getFuelCost(distance, getLadenMass());
|
||||
return engine.getFuelCost(distance, getLadenMass(getRoundMaxFuel(distance)));
|
||||
}
|
||||
|
||||
public double getFuelCost(double fuel, double distance){
|
||||
return engine.getFuelCost(distance, getLadenMass(fuel));
|
||||
}
|
||||
|
||||
public double getRoundMaxFuel(double distance){
|
||||
return getRoundMaxFuel(distance, REFILL_FUEL_STEP);
|
||||
}
|
||||
|
||||
private double getRoundMaxFuel(double distance, int step){
|
||||
double fuel = getMaxFuel(distance);
|
||||
if (fuel == 0 || fuel == tank) return fuel;
|
||||
double minFuel = engine.getFuelCost(distance, getLadenMass(0));
|
||||
fuel = Math.floor(fuel*step/tank) * tank / step;
|
||||
return fuel < minFuel ? 0 : fuel;
|
||||
}
|
||||
|
||||
public double getMaxFuel(double distance){
|
||||
double fuel = engine.getMaxFuel(distance, getLadenMass(0));
|
||||
if (fuel >= tank) return tank;
|
||||
return fuel;
|
||||
|
||||
}
|
||||
|
||||
public double getMaxJumpRange(){
|
||||
return getJumpRange(Math.min(engine.getMaxFuel(), tank));
|
||||
}
|
||||
|
||||
//Jump range with full fuel tank
|
||||
public double getJumpRange(){
|
||||
return getJumpRange(tank);
|
||||
@@ -105,7 +130,7 @@ public class Ship {
|
||||
", engine=" + engine +
|
||||
", tank=" + tank +
|
||||
", mass=" + mass +
|
||||
", maxDist=" + getJumpRange() +
|
||||
", maxDist=" + getMaxJumpRange() +
|
||||
", fullTankDist=" + getFullTankJumpRange() +
|
||||
'}';
|
||||
}
|
||||
@@ -183,6 +208,11 @@ public class Ship {
|
||||
return getMultiplier() * Math.pow(distance * (mass / getOptMass()), getPowMultiplier());
|
||||
}
|
||||
|
||||
public double getMaxFuel(double distance, double emptyTankMass){
|
||||
double f = Math.pow(getMaxFuel()/getMultiplier(), 1/getPowMultiplier())*getOptMass()/distance - emptyTankMass;
|
||||
return f < getMaxFuel() ? 0 : f;
|
||||
}
|
||||
|
||||
public double getJumpRange(double fuel, double mass){
|
||||
return Math.pow(Math.min(fuel, getMaxFuel())/getMultiplier(), 1/getPowMultiplier())*getOptMass()/mass;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user