fix check max fuel on search route
This commit is contained in:
@@ -2,8 +2,14 @@ package ru.trader.analysis;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.analysis.graph.*;
|
import ru.trader.analysis.graph.ConnectibleGraph;
|
||||||
import ru.trader.core.*;
|
import ru.trader.analysis.graph.Edge;
|
||||||
|
import ru.trader.analysis.graph.Path;
|
||||||
|
import ru.trader.analysis.graph.Vertex;
|
||||||
|
import ru.trader.core.Order;
|
||||||
|
import ru.trader.core.Profile;
|
||||||
|
import ru.trader.core.TransitVendor;
|
||||||
|
import ru.trader.core.Vendor;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -269,18 +275,18 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
|||||||
super(source, target);
|
super(source, target);
|
||||||
if (path == null) throw new IllegalArgumentException("Path must be no-null");
|
if (path == null) throw new IllegalArgumentException("Path must be no-null");
|
||||||
paths.add(path);
|
paths.add(path);
|
||||||
update(path);
|
setFuel(path.getMinFuel(), path.getMaxFuel());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected VendorsBuildEdge(BuildEdge edge) {
|
protected VendorsBuildEdge(BuildEdge edge) {
|
||||||
super(edge.getSource(), edge.getTarget());
|
super(edge.getSource(), edge.getTarget());
|
||||||
Path<Vendor> path = new Path<>(Collections.singleton(edge));
|
Path<Vendor> path = new Path<>(Collections.singleton(edge));
|
||||||
paths.add(path);
|
paths.add(path);
|
||||||
update(path);
|
setFuel(path.getMinFuel(), path.getMaxFuel());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(Path<Vendor> path){
|
private void update(Path<Vendor> path){
|
||||||
setFuel(path.getMinFuel(), path.getMaxFuel());
|
setFuel(Math.min(getMinFuel(), path.getMinFuel()), Math.max(getMaxFuel(), path.getMaxFuel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setOrders(List<Order> orders){
|
protected void setOrders(List<Order> orders){
|
||||||
@@ -307,7 +313,7 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
|||||||
public Path<Vendor> getPath(double fuel){
|
public Path<Vendor> getPath(double fuel){
|
||||||
Path<Vendor> res = null;
|
Path<Vendor> res = null;
|
||||||
for (Path<Vendor> p : paths) {
|
for (Path<Vendor> p : paths) {
|
||||||
if (fuel >= p.getMinFuel() && fuel <= p.getMaxFuel() || getSource().getEntry().canRefill()) {
|
if ((fuel >= p.getMinFuel() || getSource().getEntry().canRefill()) && fuel <= p.getMaxFuel()) {
|
||||||
if (getProfile().getPathPriority().equals(Profile.PATH_PRIORITY.FAST)) {
|
if (getProfile().getPathPriority().equals(Profile.PATH_PRIORITY.FAST)) {
|
||||||
if (res == null || (p.getSize() < res.getSize() || p.getSize() == res.getSize() && p.getFuelCost() < res.getFuelCost()) && p.getRefillCount(fuel) <= res.getRefillCount(fuel)) {
|
if (res == null || (p.getSize() < res.getSize() || p.getSize() == res.getSize() && p.getFuelCost() < res.getFuelCost()) && p.getRefillCount(fuel) <= res.getRefillCount(fuel)) {
|
||||||
res = p;
|
res = p;
|
||||||
@@ -325,27 +331,28 @@ public class VendorsGraph extends ConnectibleGraph<Vendor> {
|
|||||||
|
|
||||||
private boolean isRemove(Path<Vendor> path, Path<Vendor> best){
|
private boolean isRemove(Path<Vendor> path, Path<Vendor> best){
|
||||||
if (profile.getPathPriority() == Profile.PATH_PRIORITY.FAST){
|
if (profile.getPathPriority() == Profile.PATH_PRIORITY.FAST){
|
||||||
return path.getSize() > best.getSize() || (path.getSize() == best.getSize() && path.getFuelCost() >= best.getFuelCost()) && path.getMinFuel() >= best.getMinFuel() && path.getRefillCount() >= best.getRefillCount();
|
return (path.getSize() > best.getSize() || (path.getSize() == best.getSize() && path.getFuelCost() >= best.getFuelCost()))
|
||||||
|
&& (path.getSource().canRefill() || path.getMinFuel() >= best.getMinFuel() && path.getRefillCount() >= best.getRefillCount())
|
||||||
|
&& path.getMaxFuel() <= best.getMaxFuel();
|
||||||
}
|
}
|
||||||
return path.getMinFuel() >= best.getMinFuel() && path.getFuelCost() >= best.getFuelCost() && path.getRefillCount() >= best.getRefillCount();
|
return (path.getSource().canRefill() || path.getMinFuel() >= best.getMinFuel() && path.getRefillCount() >= best.getRefillCount())
|
||||||
|
&& path.getMaxFuel() <= best.getMaxFuel() && path.getFuelCost() >= best.getFuelCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Path<Vendor> path) {
|
public void add(Path<Vendor> path) {
|
||||||
for (Iterator<Path<Vendor>> iterator = paths.iterator(); iterator.hasNext(); ) {
|
for (Iterator<Path<Vendor>> iterator = paths.iterator(); iterator.hasNext(); ) {
|
||||||
Path<Vendor> p = iterator.next();
|
Path<Vendor> p = iterator.next();
|
||||||
if (isRemove(p, path)) {
|
|
||||||
iterator.remove();
|
|
||||||
} else {
|
|
||||||
if (isRemove(path, p)) {
|
if (isRemove(path, p)) {
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
if (isRemove(p, path)) {
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
paths.add(path);
|
paths.add(path);
|
||||||
if (getMinFuel() > path.getMinFuel()) {
|
|
||||||
update(path);
|
update(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ public class Path<T extends Connectable<T>> {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T getSource(){
|
||||||
|
return entries.get(entries.size()-1).getSource().getEntry();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder("{");
|
final StringBuilder sb = new StringBuilder("{");
|
||||||
|
|||||||
Reference in New Issue
Block a user