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