add station select on route select
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package ru.trader.core;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.graph.*;
|
||||
@@ -38,15 +37,25 @@ public class MarketAnalyzer {
|
||||
return top;
|
||||
}
|
||||
|
||||
public Collection<Order> getOrders(Vendor vendor, double balance) {
|
||||
Collection<Place> places = market.get();
|
||||
Graph<Place> graph = new Graph<Place>(vendor.getPlace(), places, tank, maxDistance, true, jumps, Path::new);
|
||||
return getOrders(graph, Collections.singleton(vendor), balance, 0);
|
||||
}
|
||||
|
||||
public Collection<Order> getOrders(Place place, double balance) {
|
||||
return getOrders(place, balance, 0);
|
||||
}
|
||||
|
||||
private Collection<Order> getOrders(Place place, double balance, double lowProfit) {
|
||||
List<Order> res = new ArrayList<>(20);
|
||||
Collection<Place> places = market.get();
|
||||
Graph<Place> graph = new Graph<>(place, places, tank, maxDistance, true, jumps, Path::new);
|
||||
for (Vendor vendor : place.get()) {
|
||||
return getOrders(graph, place.get(), balance, lowProfit);
|
||||
}
|
||||
|
||||
private Collection<Order> getOrders(Graph<Place> graph, Collection<Vendor> sellers, double balance, double lowProfit) {
|
||||
List<Order> res = new ArrayList<>(20);
|
||||
for (Vendor vendor : sellers) {
|
||||
for (Offer sell : vendor.getAllSellOffers()) {
|
||||
LOG.trace("Sell offer {}", sell);
|
||||
if (sell.getCount() == 0) continue;
|
||||
@@ -75,62 +84,77 @@ public class MarketAnalyzer {
|
||||
return res;
|
||||
}
|
||||
|
||||
public Collection<Order> getOrders(Place from, Place to, double balance) {
|
||||
Collection<Order> res = new ArrayList<>();
|
||||
Graph<Place> graph = new Graph<>(from, market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
if (!graph.isAccessible(to)){
|
||||
LOG.trace("Is inaccessible buyer");
|
||||
return res;
|
||||
}
|
||||
for (Vendor seller : from.get()) {
|
||||
private Collection<Order> getOrders(Collection<Vendor> sellers, Collection<Vendor> buyers, double balance, double lowProfit) {
|
||||
List<Order> res = new ArrayList<>();
|
||||
for (Vendor seller : sellers) {
|
||||
for (Offer sell : seller.getAllSellOffers()) {
|
||||
if (sell.getCount() == 0) continue;
|
||||
long count = Order.getMaxCount(sell, balance, cargo);
|
||||
LOG.trace("Sell offer {}, count = {}", sell, count);
|
||||
if (count == 0) continue;
|
||||
for (Vendor buyer : to.get()) {
|
||||
for (Vendor buyer : buyers) {
|
||||
Offer buy = buyer.getBuy(sell.getItem());
|
||||
if (buy != null){
|
||||
Order order = new Order(sell, buy, count);
|
||||
LOG.trace("Buy offer {} profit = {}", buy, order.getProfit());
|
||||
if (order.getProfit() < lowProfit) {
|
||||
LOG.trace("Is low profit, skip");
|
||||
continue;
|
||||
}
|
||||
res.add(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res.sort(orderComparator);
|
||||
return res;
|
||||
}
|
||||
|
||||
public Collection<Order> getOrders(Vendor from, Vendor to, double balance) {
|
||||
Collection<Order> res = new ArrayList<>();
|
||||
Graph<Place> graph = new Graph<>(from.getPlace(), market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
Graph<Place> graph = new Graph<Place>(from.getPlace(), market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
if (!graph.isAccessible(to.getPlace())){
|
||||
LOG.trace("Is inaccessible buyer");
|
||||
return res;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
for (Offer sell : from.getAllSellOffers()) {
|
||||
if (sell.getCount() == 0) continue;
|
||||
long count = Order.getMaxCount(sell, balance, cargo);
|
||||
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;
|
||||
return getOrders(Collections.singleton(from), Collections.singleton(to), balance, 0);
|
||||
}
|
||||
|
||||
public Collection<Order> getOrders(Place from, Place to, double balance) {
|
||||
Graph<Place> graph = new Graph<Place>(from, market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
if (!graph.isAccessible(to)){
|
||||
LOG.trace("Is inaccessible buyer");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getOrders(from.get(), to.get(), balance, 0);
|
||||
}
|
||||
|
||||
|
||||
public Collection<Order> getOrders(Vendor from, Place to, double balance) {
|
||||
Graph<Place> graph = new Graph<Place>(from.getPlace(), market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
if (!graph.isAccessible(to)){
|
||||
LOG.trace("Is inaccessible buyer");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getOrders(Collections.singleton(from), to.get(), balance, 0);
|
||||
}
|
||||
|
||||
public Collection<Order> getOrders(Place from, Vendor to, double balance) {
|
||||
Graph<Place> graph = new Graph<Place>(from, market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
if (!graph.isAccessible(to.getPlace())){
|
||||
LOG.trace("Is inaccessible buyer");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return getOrders(from.get(), Collections.singleton(to), balance, 0);
|
||||
}
|
||||
|
||||
|
||||
public Collection<Path<Place>> getPaths(Place from, Place to){
|
||||
Graph<Place> graph = new Graph<>(from, market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
Graph<Place> graph = new Graph<Place>(from, market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
return graph.getPathsTo(to);
|
||||
}
|
||||
|
||||
public Path<Place> getPath(Place from, Place to){
|
||||
Graph<Place> graph = new Graph<>(from, market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
Graph<Place> graph = new Graph<Place>(from, market.get(), tank, maxDistance, true, jumps, Path::new);
|
||||
return graph.getFastPathTo(to);
|
||||
}
|
||||
|
||||
@@ -139,6 +163,12 @@ public class MarketAnalyzer {
|
||||
return (PathRoute)graph.getFastPathTo(to);
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getPaths(Vendor from, double balance){
|
||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize);
|
||||
Collection<Vendor> vendors = market.getVendors();
|
||||
return searcher.getPaths(from, vendors, jumps, balance, cargo, limit);
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getPaths(Place from, double balance){
|
||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize);
|
||||
Collection<Vendor> vendors = market.getVendors();
|
||||
@@ -149,7 +179,6 @@ public class MarketAnalyzer {
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getPaths(Vendor from, Vendor to, double balance){
|
||||
@@ -173,6 +202,31 @@ public class MarketAnalyzer {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getPaths(Vendor from, Place to, double balance){
|
||||
List<PathRoute> top = new ArrayList<>(limit);
|
||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize);
|
||||
Collection<Vendor> vendors = market.getVendors();
|
||||
Collection<Vendor> toVendors = to.get();
|
||||
for (Vendor toVendor : toVendors) {
|
||||
Collection<PathRoute> paths = searcher.getPaths(from, toVendor, vendors, jumps, balance, cargo, limit);
|
||||
TopList.addAllToTop(top, paths, limit, RouteGraph.byProfitComparator);
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getPaths(Place from, Vendor to, double balance){
|
||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize);
|
||||
Collection<Vendor> vendors = market.getVendors();
|
||||
Collection<Vendor> fVendors = from.get();
|
||||
for (Vendor fromVendor : fVendors) {
|
||||
Collection<PathRoute> paths = searcher.getPaths(fromVendor, to, vendors, jumps, balance, cargo, limit);
|
||||
if (paths.size()>0){
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Collection<PathRoute> getTopPaths(double balance){
|
||||
List<PathRoute> top = new ArrayList<>(limit);
|
||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize);
|
||||
|
||||
Reference in New Issue
Block a user