- update paths layout
- add top routers - add orders button
This commit is contained in:
@@ -60,6 +60,42 @@ public class MarketAnalyzer {
|
||||
return top;
|
||||
}
|
||||
|
||||
public Collection<Order> getOrders(Vendor vendor, double balance) {
|
||||
Collection<Order> res = new ArrayList<>();
|
||||
for (Offer sell : vendor.getAllSellOffers()) {
|
||||
long count = Math.min(cargo, (long) Math.floor(balance / sell.getPrice()));
|
||||
LOG.trace("Sell offer {}, count = {}", sell, count);
|
||||
if (count == 0) continue;
|
||||
Iterator<Offer> buyers = market.getStatBuy(sell.getItem()).getOffers().descendingIterator();
|
||||
while (buyers.hasNext()){
|
||||
Offer buy = buyers.next();
|
||||
Order order = new Order(sell, buy, count);
|
||||
LOG.trace("Buy offer {} profit = {}", buy, order.getProfit());
|
||||
res.add(order);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public Collection<Order> getOrders(Vendor from, Vendor to, double balance) {
|
||||
Collection<Order> res = new ArrayList<>();
|
||||
for (Offer sell : from.getAllSellOffers()) {
|
||||
long count = Math.min(cargo, (long) Math.floor(balance / sell.getPrice()));
|
||||
LOG.trace("Sell offer {}, count = {}", sell, count);
|
||||
if (count == 0) continue;
|
||||
|
||||
Offer buy = to.getBuy(sell.getItem());
|
||||
if (buy != null){
|
||||
Order order = new Order(sell, buy, count);
|
||||
LOG.trace("Buy offer {} profit = {}", buy, order.getProfit());
|
||||
res.add(order);
|
||||
}
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
private void rebuild(Vendor source){
|
||||
graph = new Graph<>(source, market.get(), tank, maxDistance, true, jumps, PathRoute::new);
|
||||
}
|
||||
@@ -74,6 +110,22 @@ public class MarketAnalyzer {
|
||||
return graph.getPathsTo(to, true);
|
||||
}
|
||||
|
||||
public Path<Vendor> getPath(Vendor from, Vendor to){
|
||||
setSource(from);
|
||||
return graph.getFastPathTo(to);
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getPaths(Vendor from, double balance){
|
||||
Collection<PathRoute> res = new ArrayList<>();
|
||||
for (Vendor vendor : market.get()) {
|
||||
PathRoute path = (PathRoute) getPath(from, vendor);
|
||||
if (path == null) continue;
|
||||
path.sort(balance, cargo);
|
||||
res.add(path);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getPaths(Vendor from, Vendor to, double balance){
|
||||
Collection<Path<Vendor>> paths = getPaths(from, to);
|
||||
Collection<PathRoute> res = new ArrayList<>(paths.size());
|
||||
@@ -85,6 +137,21 @@ public class MarketAnalyzer {
|
||||
return res;
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getTopPaths(int limit, double balance){
|
||||
TreeSet<PathRoute> top = new TreeSet<>((p1, p2) -> Double.compare(p2.getProfit(), p1.getProfit()));
|
||||
for (Vendor vendor : market.get()) {
|
||||
Collection<PathRoute> paths = getPaths(vendor, vendor, balance);
|
||||
for (PathRoute path : paths) {
|
||||
top.add(path);
|
||||
if (top.size() > limit) {
|
||||
top.pollLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
|
||||
public void setTank(double tank) {
|
||||
this.tank = tank;
|
||||
this.graph = null;
|
||||
@@ -107,4 +174,5 @@ public class MarketAnalyzer {
|
||||
public long getCargo() {
|
||||
return cargo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -142,6 +142,7 @@ public class Graph<T extends Connectable<T>> {
|
||||
|
||||
public Path<T> getFastPathTo(T entry){
|
||||
Vertex<T> target = getVertex(entry);
|
||||
if (target == null) return null;
|
||||
return findFastPath(pathFabric.build(root), target, target.getLevel()+1, stock);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class PathRoute extends Path<Vendor> {
|
||||
}
|
||||
|
||||
public PathRoute getCopy(){
|
||||
PathRoute path = (PathRoute) getRoot();
|
||||
PathRoute path = getRoot();
|
||||
PathRoute res = new PathRoute(path.getTarget());
|
||||
while (path.hasNext()){
|
||||
path = path.getNext();
|
||||
@@ -180,11 +180,11 @@ public class PathRoute extends Path<Vendor> {
|
||||
}
|
||||
|
||||
private void backwardSort(){
|
||||
if (isRoot()) return;
|
||||
orders.sort(this::compareOrders);
|
||||
LOG.trace("New order of orders {}", orders);
|
||||
updateProfit();
|
||||
getPrevious().backwardSort();
|
||||
if (!isRoot())
|
||||
getPrevious().backwardSort();
|
||||
}
|
||||
|
||||
private void updateBalance() {
|
||||
@@ -209,10 +209,10 @@ public class PathRoute extends Path<Vendor> {
|
||||
|
||||
|
||||
private void updateProfit() {
|
||||
Order best = orders.get(0);
|
||||
Order best = orders.isEmpty()? TRANSIT : orders.get(0);
|
||||
if (best == TRANSIT) profit = getTransitProfit();
|
||||
else profit = getProfit(best);
|
||||
LOG.trace("Max profit from {} = {}", getPrevious().get(), profit);
|
||||
LOG.trace("Max profit from {} = {}", isRoot() ? get() : getPrevious().get(), profit);
|
||||
}
|
||||
|
||||
private double getTransitProfit(){
|
||||
|
||||
Reference in New Issue
Block a user