compute route score as time/profit
This commit is contained in:
@@ -8,16 +8,15 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/*TODO: change to compute profit for seocnd
|
||||
* times:
|
||||
* 26810 - 7:15
|
||||
* 1980 - 3:46
|
||||
* 1330 - 2:47
|
||||
* 1380 - 2:32
|
||||
* 780 - 2:10
|
||||
* 430 - 2:04
|
||||
* 306 - 1:54
|
||||
* 88 - 1:25
|
||||
/* times:
|
||||
* 26810 - 7:15 - 435
|
||||
* 1980 - 3:46 - 226
|
||||
* 1330 - 2:47 - 167
|
||||
* 1380 - 2:32 - 152
|
||||
* 780 - 2:10 - 130
|
||||
* 430 - 2:04 - 124
|
||||
* 306 - 1:54 - 116
|
||||
* 88 - 1:25 - 85
|
||||
*
|
||||
* launch_to_start_jmp - 0:40, 0:43, 0:40
|
||||
* jmp - 0:33, 0:33, 0:30, 0:32, 0:32, 0:32
|
||||
@@ -84,6 +83,10 @@ public class Scorer {
|
||||
return avgProfit * profile.getShip().getCargo();
|
||||
}
|
||||
|
||||
public double getMaxProfit() {
|
||||
return maxProfit;
|
||||
}
|
||||
|
||||
public double getMaxScore() {
|
||||
return maxScore;
|
||||
}
|
||||
@@ -101,38 +104,33 @@ public class Scorer {
|
||||
return getScore(vendor.getDistance(), profit, jumps, lands, fuel);
|
||||
}
|
||||
|
||||
public double getTransitScore(double fuel){
|
||||
LOG.trace("Compute transit score fuel={}", fuel);
|
||||
double profit = maxProfit;
|
||||
profit -= profile.getFuelPrice() * fuel / profile.getShip().getCargo();
|
||||
if (avgDistance > 0) {
|
||||
profit -= - avgProfit * profile.getDistanceMult();
|
||||
private double getTime(double distance){
|
||||
double a = 6000;
|
||||
double b = 673;
|
||||
double c = 1670;
|
||||
return Math.log(distance + a)*b*profile.getDistanceTime() - c;
|
||||
}
|
||||
|
||||
public double getProfit(double profit, double fuel){
|
||||
profit -= profile.getFuelPrice() * fuel;
|
||||
profit = profit / profile.getShip().getCargo();
|
||||
return profit;
|
||||
}
|
||||
|
||||
public double getTime(double distance, int jumps, int lands){
|
||||
double time = profile.getTakeoffTime();
|
||||
if (jumps > 0){
|
||||
time += profile.getJumpTime() + (jumps-1) * (profile.getRechargeTime() + profile.getJumpTime());
|
||||
}
|
||||
if (profile.getLandMult() > 0){
|
||||
profit = profit / profile.getLandMult();
|
||||
if (profile.getLandingTime() > 0){
|
||||
time += (lands-1)*(getTime(avgDistance) + profile.getLandingTime() + profile.getTakeoffTime()) + getTime(distance) + profile.getLandingTime();
|
||||
}
|
||||
double score = profit * (1 - profile.getJumpMult()/profile.getJumps());
|
||||
LOG.trace("score={}", score);
|
||||
return score;
|
||||
return time;
|
||||
}
|
||||
|
||||
public double getScore(double distance, double profit, int jumps, int lands, double fuel){
|
||||
LOG.trace("Compute score distance={}, profit={}, jumps={}, lands={}, fuel={}", distance, profit, jumps, lands, fuel);
|
||||
profit -= profile.getFuelPrice() * fuel;
|
||||
profit = profit / profile.getShip().getCargo();
|
||||
if (avgDistance > 0) {
|
||||
profit -= avgProfit * profile.getDistanceMult() * (distance - avgDistance) / avgDistance;
|
||||
}
|
||||
double score = profit;
|
||||
if (profit > 0){
|
||||
if (lands > 0 && profile.getLandMult() > 0){
|
||||
score = profit / (lands * profile.getLandMult());
|
||||
}
|
||||
if (profile.getPathPriority() == Profile.PATH_PRIORITY.ECO){
|
||||
jumps = 1;
|
||||
}
|
||||
score -= profile.getJumpMult()/profile.getJumps() * score * jumps;
|
||||
}
|
||||
double score = getProfit(profit, fuel)/getTime(distance, jumps, lands);
|
||||
LOG.trace("score={}", score);
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.trader.analysis;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.analysis.graph.*;
|
||||
@@ -397,6 +398,8 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
||||
public class VendorsEdge extends ConnectibleEdge<Vendor> {
|
||||
private TransitPath path;
|
||||
private List<Order> orders;
|
||||
private Double profitByTonne;
|
||||
private Double time;
|
||||
|
||||
protected VendorsEdge(Vertex<Vendor> source, Vertex<Vendor> target, TransitPath path) {
|
||||
super(source, target);
|
||||
@@ -433,19 +436,54 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
||||
return path;
|
||||
}
|
||||
|
||||
public double getProfitByTonne() {
|
||||
if (profitByTonne == null){
|
||||
profitByTonne = computeProfit();
|
||||
}
|
||||
return profitByTonne;
|
||||
}
|
||||
|
||||
public double getTime() {
|
||||
if (time == null){
|
||||
time = computeTime();
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Edge other) {
|
||||
double w = getWeight();
|
||||
double ow = other.getWeight();
|
||||
if (ow >= 0 && w >= 0) return super.compareTo(other);
|
||||
if (w < 0 && ow < 0) return Double.compare(Math.abs(w), Math.abs(ow));
|
||||
return w < 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
protected double computeProfit(){
|
||||
double fuel = fuelCost;
|
||||
if (path != null){
|
||||
fuel = path.getFuelCost();
|
||||
}
|
||||
return scorer.getProfit(getProfit(), fuel);
|
||||
}
|
||||
|
||||
protected double computeTime(){
|
||||
int jumps = source.getEntry().getPlace().equals(target.getEntry().getPlace())? 0 : 1;
|
||||
int lands = 1;
|
||||
if (path != null){
|
||||
jumps = path.size()-1;
|
||||
lands += path.getRefillCount();
|
||||
//not lands if refuel on this station
|
||||
if (path.isRefill()) lands--;
|
||||
} else {
|
||||
lands += isRefill() ? 1 :0;
|
||||
}
|
||||
return scorer.getTime(target.getEntry().getDistance(), jumps, lands);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double computeWeight() {
|
||||
int jumps = source.getEntry().getPlace().equals(target.getEntry().getPlace())? 0 : 1;
|
||||
int lands = 1; double fuel = fuelCost;
|
||||
if (path != null){
|
||||
jumps = path.size()-1; fuel = getFuelCost();
|
||||
lands += path.getRefillCount();
|
||||
}
|
||||
double profit = getProfit();
|
||||
double score = scorer.getScore(target.getEntry(), profit, jumps, lands, fuel);
|
||||
score = scorer.getMaxScore() - score;
|
||||
if (score < 0) score = 0;
|
||||
return score;
|
||||
return getTime()/getProfitByTonne();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -536,12 +574,23 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
||||
@Override
|
||||
public double getWeight() {
|
||||
if (weight == null){
|
||||
Edge<Vendor> edge = getEdge();
|
||||
VendorsEdge edge = (VendorsEdge) getEdge();
|
||||
Optional<Traversal<Vendor>> head = getHead();
|
||||
weight = (head.isPresent() ? ((VendorsTraversalEntry)head.get()).getWeight() : 0) + (edge != null ? edge.getWeight() : 0);
|
||||
double profit = 0; double time = 0;
|
||||
if (edge != null){
|
||||
weight = weight / (1+Math.floorDiv(profile.getLands() - this.size(),this.size()));
|
||||
profit = edge.getProfitByTonne();
|
||||
time = edge.getTime();
|
||||
}
|
||||
while (head.isPresent()){
|
||||
VendorsTraversalEntry hEntry = (VendorsTraversalEntry) head.get();
|
||||
edge = (VendorsEdge) hEntry.getEdge();
|
||||
if (edge != null){
|
||||
profit += edge.getProfitByTonne();
|
||||
time += edge.getTime();
|
||||
}
|
||||
head = hEntry.getHead();
|
||||
}
|
||||
weight = profit > 1 ? time / profit : time;
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ public class Profile {
|
||||
private boolean refill;
|
||||
private int routesCount;
|
||||
//Scorer multipliers
|
||||
private double distanceMult;
|
||||
private double jumpMult;
|
||||
private double landMult;
|
||||
private double distanceTime;
|
||||
private double jumpTime;
|
||||
private double landingTime;
|
||||
private double takeoffTime;
|
||||
private double rechargeTime;
|
||||
private double fuelPrice;
|
||||
private PATH_PRIORITY pathPriority;
|
||||
|
||||
@@ -24,10 +26,12 @@ public class Profile {
|
||||
jumps = 6;
|
||||
lands = 4;
|
||||
routesCount = 30;
|
||||
distanceMult = 0.8;
|
||||
landMult = 0.95;
|
||||
distanceTime = 0.3;
|
||||
fuelPrice = 100;
|
||||
jumpMult = 0.5;
|
||||
landingTime = 80;
|
||||
takeoffTime = 40;
|
||||
jumpTime = 32;
|
||||
rechargeTime = 12;
|
||||
pathPriority = PATH_PRIORITY.FAST;
|
||||
}
|
||||
|
||||
@@ -79,28 +83,44 @@ public class Profile {
|
||||
this.routesCount = routesCount;
|
||||
}
|
||||
|
||||
public double getDistanceMult() {
|
||||
return distanceMult;
|
||||
public double getDistanceTime() {
|
||||
return distanceTime;
|
||||
}
|
||||
|
||||
public void setDistanceMult(double distanceMult) {
|
||||
this.distanceMult = distanceMult;
|
||||
public void setDistanceTime(double distanceTime) {
|
||||
this.distanceTime = distanceTime;
|
||||
}
|
||||
|
||||
public double getJumpMult() {
|
||||
return jumpMult;
|
||||
public double getJumpTime() {
|
||||
return jumpTime;
|
||||
}
|
||||
|
||||
public void setJumpMult(double jumpMult) {
|
||||
this.jumpMult = jumpMult;
|
||||
public void setJumpTime(double jumpTime) {
|
||||
this.jumpTime = jumpTime;
|
||||
}
|
||||
|
||||
public double getLandMult() {
|
||||
return landMult;
|
||||
public double getLandingTime() {
|
||||
return landingTime;
|
||||
}
|
||||
|
||||
public void setLandMult(double landMult) {
|
||||
this.landMult = landMult;
|
||||
public void setLandingTime(double landingTime) {
|
||||
this.landingTime = landingTime;
|
||||
}
|
||||
|
||||
public double getTakeoffTime() {
|
||||
return takeoffTime;
|
||||
}
|
||||
|
||||
public void setTakeoffTime(double takeoffTime) {
|
||||
this.takeoffTime = takeoffTime;
|
||||
}
|
||||
|
||||
public double getRechargeTime() {
|
||||
return rechargeTime;
|
||||
}
|
||||
|
||||
public void setRechargeTime(double rechargeTime) {
|
||||
this.rechargeTime = rechargeTime;
|
||||
}
|
||||
|
||||
public double getFuelPrice() {
|
||||
@@ -124,13 +144,15 @@ public class Profile {
|
||||
Profile profile = new Profile(ship);
|
||||
profile.setBalance(Double.valueOf(values.getProperty("profile.balance","1000")));
|
||||
profile.setJumps(Integer.valueOf(values.getProperty("profile.jumps", "6")));
|
||||
profile.setLands(Integer.valueOf(values.getProperty("profile.lands","4")));
|
||||
profile.setPathPriority(PATH_PRIORITY.valueOf(values.getProperty("profile.search.priority","FAST")));
|
||||
profile.setRoutesCount(Integer.valueOf(values.getProperty("profile.search.routes","100")));
|
||||
profile.setFuelPrice(Double.valueOf(values.getProperty("profile.search.fuel.price","100")));
|
||||
profile.setDistanceMult(Double.valueOf(values.getProperty("profile.search.mult.distance","0.8")));
|
||||
profile.setLandMult(Double.valueOf(values.getProperty("profile.search.mult.land","0.95")));
|
||||
profile.setJumpMult(Double.valueOf(values.getProperty("profile.search.mult.jump","0.5")));
|
||||
profile.setLands(Integer.valueOf(values.getProperty("profile.lands", "4")));
|
||||
profile.setPathPriority(PATH_PRIORITY.valueOf(values.getProperty("profile.search.priority", "FAST")));
|
||||
profile.setRoutesCount(Integer.valueOf(values.getProperty("profile.search.routes", "100")));
|
||||
profile.setFuelPrice(Double.valueOf(values.getProperty("profile.search.fuel.price", "100")));
|
||||
profile.setDistanceTime(Double.valueOf(values.getProperty("profile.search.times.distance", "0.3")));
|
||||
profile.setLandingTime(Double.valueOf(values.getProperty("profile.search.times.landing", "80")));
|
||||
profile.setTakeoffTime(Double.valueOf(values.getProperty("profile.search.times.takeoff", "40")));
|
||||
profile.setJumpTime(Double.valueOf(values.getProperty("profile.search.times.jump", "32")));
|
||||
profile.setRechargeTime(Double.valueOf(values.getProperty("profile.search.times.recharge", "12")));
|
||||
return profile;
|
||||
}
|
||||
|
||||
@@ -141,9 +163,11 @@ public class Profile {
|
||||
values.setProperty("profile.search.priority", String.valueOf(pathPriority));
|
||||
values.setProperty("profile.search.routes", String.valueOf(routesCount));
|
||||
values.setProperty("profile.search.fuel.price", String.valueOf(fuelPrice));
|
||||
values.setProperty("profile.search.mult.distance", String.valueOf(distanceMult));
|
||||
values.setProperty("profile.search.mult.land", String.valueOf(landMult));
|
||||
values.setProperty("profile.search.mult.jump", String.valueOf(jumpMult));
|
||||
values.setProperty("profile.search.times.distance", String.valueOf(distanceTime));
|
||||
values.setProperty("profile.search.times.landing", String.valueOf(landingTime));
|
||||
values.setProperty("profile.search.times.takeoff", String.valueOf(takeoffTime));
|
||||
values.setProperty("profile.search.times.jump", String.valueOf(jumpTime));
|
||||
values.setProperty("profile.search.times.recharge", String.valueOf(rechargeTime));
|
||||
ship.writeTo(values);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user