Archived
0

don't search in all vendors if lands count less min hop

This commit is contained in:
iMoHax
2015-09-09 17:08:00 +03:00
parent 8536e78458
commit e1d8dcc680
3 changed files with 36 additions and 9 deletions

View File

@@ -62,6 +62,10 @@ public class CrawlerSpecificator {
}
}
public void buy(Offer offer){
offers.add(offer);
}
public void buy(Collection<Offer> offers){
this.offers.addAll(offers);
}
@@ -70,6 +74,21 @@ public class CrawlerSpecificator {
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){
RouteSpecification<Vendor> res = null;
for (Offer offer : offers) {

View File

@@ -5,6 +5,7 @@ import ru.trader.analysis.graph.Traversal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
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) {
this.all = all;
this.targetOnly = targetOnly;
this.targets = new ArrayList<>(targets);
this.targets = new HashSet<>(targets);
}
@Override

View File

@@ -186,7 +186,7 @@ public class MarketAnalyzer {
public Collection<Route> getTopRoutes(int limit){
LOG.debug("Get top {}", limit);
LimitedQueue<Route> top = new LimitedQueue<>(limit);
Collection<Vendor> vendors = getVendors();
Collection<Vendor> vendors = getVendors(new CrawlerSpecificator());
callback.start(vendors.size());
Iterator<Vendor> iterator = market.getMarkets(false).iterator();
while (iterator.hasNext()){
@@ -203,11 +203,11 @@ public class MarketAnalyzer {
}
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){
return getRoutes(getVendors(from), getVendors(), specificator);
return getRoutes(getVendors(from), getVendors(specificator), specificator);
}
public Collection<Route> getRoutes(Place from, Place to){
@@ -220,13 +220,14 @@ public class MarketAnalyzer {
}
public Collection<Route> getRoutes(Vendor from, CrawlerSpecificator specificator){
specificator.any(getVendors());
return searcher.search(from, from, getVendors(), profile.getRoutesCount(), specificator);
Collection<Vendor> vendors = getVendors(specificator);
specificator.any(vendors);
return searcher.search(from, from, vendors, profile.getRoutesCount(), specificator);
}
public Collection<Route> getRoutes(Vendor from, Place to, CrawlerSpecificator specificator){
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){
@@ -236,7 +237,7 @@ public class MarketAnalyzer {
}
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){
@@ -283,7 +284,13 @@ public class MarketAnalyzer {
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());
}