don't search in all vendors if lands count less min hop
This commit is contained in:
@@ -62,6 +62,10 @@ public class CrawlerSpecificator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void buy(Offer offer){
|
||||||
|
offers.add(offer);
|
||||||
|
}
|
||||||
|
|
||||||
public void buy(Collection<Offer> offers){
|
public void buy(Collection<Offer> offers){
|
||||||
this.offers.addAll(offers);
|
this.offers.addAll(offers);
|
||||||
}
|
}
|
||||||
@@ -70,6 +74,21 @@ public class CrawlerSpecificator {
|
|||||||
this.groupCount = groupCount;
|
this.groupCount = groupCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMinHop(){
|
||||||
|
return all.size() + (any.isEmpty() ? 0 : 1) + (containsAny.isEmpty() ? 0 : 1) + offers.size()/4 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(Vendor vendor){
|
||||||
|
boolean res = all.contains(vendor) || any.contains(vendor) || containsAny.contains(vendor);
|
||||||
|
if (res) return true;
|
||||||
|
for (Offer offer : offers) {
|
||||||
|
Offer sell = vendor.getSell(offer.getItem());
|
||||||
|
res = sell != null && sell.getCount() >= offer.getCount();
|
||||||
|
if (res) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private RouteSpecification<Vendor> buildOffersSpec(Collection<Vendor> vendors){
|
private RouteSpecification<Vendor> buildOffersSpec(Collection<Vendor> vendors){
|
||||||
RouteSpecification<Vendor> res = null;
|
RouteSpecification<Vendor> res = null;
|
||||||
for (Offer offer : offers) {
|
for (Offer offer : offers) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import ru.trader.analysis.graph.Traversal;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class RouteSpecificationByTargets<T> implements RouteSpecification<T> {
|
public class RouteSpecificationByTargets<T> implements RouteSpecification<T> {
|
||||||
@@ -15,7 +16,7 @@ public class RouteSpecificationByTargets<T> implements RouteSpecification<T> {
|
|||||||
private RouteSpecificationByTargets(Collection<T> targets, boolean all, boolean targetOnly) {
|
private RouteSpecificationByTargets(Collection<T> targets, boolean all, boolean targetOnly) {
|
||||||
this.all = all;
|
this.all = all;
|
||||||
this.targetOnly = targetOnly;
|
this.targetOnly = targetOnly;
|
||||||
this.targets = new ArrayList<>(targets);
|
this.targets = new HashSet<>(targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ public class MarketAnalyzer {
|
|||||||
public Collection<Route> getTopRoutes(int limit){
|
public Collection<Route> getTopRoutes(int limit){
|
||||||
LOG.debug("Get top {}", limit);
|
LOG.debug("Get top {}", limit);
|
||||||
LimitedQueue<Route> top = new LimitedQueue<>(limit);
|
LimitedQueue<Route> top = new LimitedQueue<>(limit);
|
||||||
Collection<Vendor> vendors = getVendors();
|
Collection<Vendor> vendors = getVendors(new CrawlerSpecificator());
|
||||||
callback.start(vendors.size());
|
callback.start(vendors.size());
|
||||||
Iterator<Vendor> iterator = market.getMarkets(false).iterator();
|
Iterator<Vendor> iterator = market.getMarkets(false).iterator();
|
||||||
while (iterator.hasNext()){
|
while (iterator.hasNext()){
|
||||||
@@ -203,11 +203,11 @@ public class MarketAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Route> getLoops(Vendor vendor, CrawlerSpecificator specificator){
|
public Collection<Route> getLoops(Vendor vendor, CrawlerSpecificator specificator){
|
||||||
return searcher.searchLoops(vendor, getVendors(), specificator);
|
return searcher.searchLoops(vendor, getVendors(specificator), specificator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Route> getRoutes(Place from, CrawlerSpecificator specificator){
|
public Collection<Route> getRoutes(Place from, CrawlerSpecificator specificator){
|
||||||
return getRoutes(getVendors(from), getVendors(), specificator);
|
return getRoutes(getVendors(from), getVendors(specificator), specificator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Route> getRoutes(Place from, Place to){
|
public Collection<Route> getRoutes(Place from, Place to){
|
||||||
@@ -220,13 +220,14 @@ public class MarketAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Route> getRoutes(Vendor from, CrawlerSpecificator specificator){
|
public Collection<Route> getRoutes(Vendor from, CrawlerSpecificator specificator){
|
||||||
specificator.any(getVendors());
|
Collection<Vendor> vendors = getVendors(specificator);
|
||||||
return searcher.search(from, from, getVendors(), profile.getRoutesCount(), specificator);
|
specificator.any(vendors);
|
||||||
|
return searcher.search(from, from, vendors, profile.getRoutesCount(), specificator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Route> getRoutes(Vendor from, Place to, CrawlerSpecificator specificator){
|
public Collection<Route> getRoutes(Vendor from, Place to, CrawlerSpecificator specificator){
|
||||||
specificator.any(getVendors(to));
|
specificator.any(getVendors(to));
|
||||||
return searcher.search(from, from, getVendors(), profile.getRoutesCount(), specificator);
|
return searcher.search(from, from, getVendors(specificator), profile.getRoutesCount(), specificator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Route> getRoutes(Vendor from, Vendor to){
|
public Collection<Route> getRoutes(Vendor from, Vendor to){
|
||||||
@@ -236,7 +237,7 @@ public class MarketAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Route> getRoutes(Vendor from, Vendor to, CrawlerSpecificator specificator){
|
public Collection<Route> getRoutes(Vendor from, Vendor to, CrawlerSpecificator specificator){
|
||||||
return searcher.search(from, to, getVendors(), profile.getRoutesCount(), specificator);
|
return searcher.search(from, to, getVendors(specificator), profile.getRoutesCount(), specificator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Route> getRoutes(Collection<Vendor> fVendors, Collection<Vendor> vendors, CrawlerSpecificator specificator){
|
public List<Route> getRoutes(Collection<Vendor> fVendors, Collection<Vendor> vendors, CrawlerSpecificator specificator){
|
||||||
@@ -283,7 +284,13 @@ public class MarketAnalyzer {
|
|||||||
return market.get().collect(Collectors.toList());
|
return market.get().collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Vendor> getVendors(){
|
private List<Vendor> getVendors(CrawlerSpecificator specificator){
|
||||||
|
List<Vendor> vendors;
|
||||||
|
if (specificator.getMinHop() >= profile.getLands()){
|
||||||
|
vendors = market.get().map(Place::asTransit).collect(Collectors.toList());
|
||||||
|
market.getVendors().filter(specificator::contains).forEach(vendors::add);
|
||||||
|
return vendors;
|
||||||
|
}
|
||||||
return market.getMarkets(true).collect(Collectors.toList());
|
return market.getMarkets(true).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user