Archived
0

add callbacks to crawler

This commit is contained in:
iMoHax
2015-07-31 10:58:01 +03:00
parent 40b0f66d8d
commit eb9f42ddb6
18 changed files with 180 additions and 297 deletions

View File

@@ -58,11 +58,11 @@ public class VendorsGraphTest extends Assert {
profile.setBalance(100000); profile.setJumps(6);
Scorer scorer = new Scorer(fWorld, profile);
LOG.info("Build vendors graph");
VendorsGraph vGraph = new VendorsGraph(scorer);
VendorsGraph vGraph = new VendorsGraph(scorer, new AnalysisCallBack());
vGraph.build(cabreraDock, fWorld.getMarkets(true).collect(Collectors.toList()));
LOG.info("Search");
SimpleCollector<Vendor> paths = new SimpleCollector<>();
Crawler<Vendor> crawler = vGraph.crawler(paths::add);
Crawler<Vendor> crawler = vGraph.crawler(paths::add, new AnalysisCallBack());
// Cabrera Dock -> Transit Wolf 1323 -> Transit Wolf 1325 -> Quimper Ring -> Transit Bhadaba -> Transit Wolf 1325 -> Cabrera Dock]
crawler.findMin(cabreraDock, 100);
assertEquals(100, paths.get().size());
@@ -189,7 +189,7 @@ public class VendorsGraphTest extends Assert {
LOG.info("Start build test");
profile.setBalance(100000); profile.setJumps(6);
LOG.info("Build connectible graph");
ConnectibleGraph<Vendor> vGraph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Vendor> vGraph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
vGraph.build(cabreraDock, fWorld.getMarkets(true).collect(Collectors.toList()));
for (Vertex<Vendor> vertex : vGraph.vertexes()) {
assertEquals(edgesStat.get(vertex.getEntry().toString()).intValue(), vertex.getEdges().size());
@@ -197,7 +197,7 @@ public class VendorsGraphTest extends Assert {
LOG.info("Build vendors graph");
Scorer scorer = new Scorer(fWorld, profile);
vGraph = new VendorsGraph(scorer);
vGraph = new VendorsGraph(scorer, new AnalysisCallBack());
vGraph.build(cabreraDock, fWorld.getMarkets(true).collect(Collectors.toList()));
for (Vertex<Vendor> vertex : vGraph.vertexes()) {
switch (vertex.getEntry().getName()){
@@ -224,11 +224,11 @@ public class VendorsGraphTest extends Assert {
profile.setBalance(100000); profile.setJumps(6);
Scorer scorer = new Scorer(fWorld, profile);
LOG.info("Build vendors graph");
VendorsGraph vGraph = new VendorsGraph(scorer);
VendorsGraph vGraph = new VendorsGraph(scorer, new AnalysisCallBack());
vGraph.build(cabreraDock, fWorld.getMarkets(true).collect(Collectors.toList()));
LOG.info("Search");
SimpleCollector<Vendor> paths = new SimpleCollector<>();
Crawler<Vendor> crawler = vGraph.crawler(new LoopRouteSpecification<>(true), paths::add);
Crawler<Vendor> crawler = vGraph.crawler(new LoopRouteSpecification<>(true), paths::add, new AnalysisCallBack());
crawler.findMin(cabreraDock, 100);
assertEquals(60, paths.get().size());
Collection<Vendor> vendors = new ArrayList<>(60);

View File

@@ -7,6 +7,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.TestUtil;
import ru.trader.analysis.AnalysisCallBack;
import ru.trader.core.Profile;
import ru.trader.core.Ship;
@@ -68,12 +69,12 @@ public class CrawlerTest extends Assert {
Profile profile = new Profile(ship);
profile.setJumps(2); profile.setRefill(false);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5 <-> x4, x5 <-> x6
SimpleCollector<Point> paths = new SimpleCollector<>();
Crawler<Point> crawler = new CCrawler<>(graph, paths::add);
Crawler<Point> crawler = new CCrawler<>(graph, paths::add, new AnalysisCallBack());
crawler.findMin(x4, 10);
TestUtil.assertPaths(paths.get(), PPath.of(x5, x4));
paths.clear();
@@ -97,12 +98,12 @@ public class CrawlerTest extends Assert {
Profile profile = new Profile(ship);
profile.setJumps(3); profile.setRefill(false);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5 <-> x4 <-> x3 <-> x2, x5 <-> x6 <-> x7 <-> x8
// x5 <-> x3, x4 <-> x2, x3 <-> x6, x4 <-> x6
SimpleCollector<Point> paths = new SimpleCollector<>();
Crawler<Point> crawler = new CCrawler<>(graph, paths::add);
Crawler<Point> crawler = new CCrawler<>(graph, paths::add, new AnalysisCallBack());
crawler.findMin(x8, 10);
TestUtil.assertPaths(paths.get(), PPath.of(x5, x6, x7, x8));
@@ -161,12 +162,12 @@ public class CrawlerTest extends Assert {
Profile profile = new Profile(ship);
profile.setJumps(3); profile.setRefill(false);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5 <-> x4 <- refill -> x3 <- refill -> x2, x5 <-> x6
// x5 <-> x3 <- refill -> x2, x5 <-> x4 <- refill -> x6
SimpleCollector<Point> paths = new SimpleCollector<>();
Crawler<Point> crawler = new CCrawler<>(graph, paths::add);
Crawler<Point> crawler = new CCrawler<>(graph, paths::add, new AnalysisCallBack());
crawler.findMin(x1, 10);
assertTrue(paths.get().isEmpty());
@@ -202,14 +203,14 @@ public class CrawlerTest extends Assert {
Profile profile = new Profile(ship);
profile.setJumps(4);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5 <-> x4 <-> x3 - refill -> x2,
// x5 <-> x6 <-> x4 <-refill -> x2
// x5 <-> x3 <- refill -> x2
// x5 <-> x4 <- refill -> x6
SimpleCollector<Point> paths = new SimpleCollector<>();
Crawler<Point> crawler = new CCrawler<>(graph, paths::add);
Crawler<Point> crawler = new CCrawler<>(graph, paths::add, new AnalysisCallBack());
crawler.findMin(x1, 10);
assertTrue(paths.get().isEmpty());
@@ -255,14 +256,14 @@ public class CrawlerTest extends Assert {
Profile profile = new Profile(ship);
profile.setJumps(4);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5 <-> x4 <-> x3 - refill -> x2,
// x5 <-> x6 <-> x4 <-refill -> x2
// x5 <-> x3 <- refill -> x2
// x5 <-> x4 <- refill -> x6
SimpleCollector<Point> paths = new SimpleCollector<>();
CCrawler<Point> crawler = new CCrawler<>(graph, paths::add);
CCrawler<Point> crawler = new CCrawler<>(graph, paths::add, new AnalysisCallBack());
crawler.setStartFuel(0.3);
crawler.findMin(x3, x2);

View File

@@ -6,6 +6,7 @@ import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.analysis.AnalysisCallBack;
import ru.trader.core.Profile;
import ru.trader.core.Ship;
@@ -51,7 +52,7 @@ public class GraphTest extends Assert {
profile.setJumps(10);
profile.setRefill(false);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5
assertFalse(graph.isAccessible(x1));
@@ -76,7 +77,7 @@ public class GraphTest extends Assert {
Profile profile = new Profile(ship);
profile.setJumps(2);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5 <-> x4 <-refill-> x3, x5 -> x6
assertFalse(graph.isAccessible(x1));
@@ -121,7 +122,7 @@ public class GraphTest extends Assert {
Profile profile = new Profile(ship);
profile.setJumps(3);profile.setRefill(false);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5 <-> x4 <-> x3, x5 <-> x6
assertFalse(graph.isAccessible(x1));
@@ -158,7 +159,7 @@ public class GraphTest extends Assert {
Profile profile = new Profile(ship);
profile.setJumps(3); profile.setRefill(false);
LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps());
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile);
ConnectibleGraph<Point> graph = new ConnectibleGraph<>(profile, new AnalysisCallBack());
graph.build(x5, entrys);
// x5 <-> x4 <-> x3 -> x2, x5 <-> x6 <-> x7 -> x8
// x5 <-> x3, x5 <-> x4 <-> x2, x3 <-> x6, x4 <-> x6

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@@ -12,9 +13,8 @@ import java.util.stream.Collectors;
public class SimpleCollector<T> {
private List<List<Edge<T>>> paths = new ArrayList<>();
public boolean add(List<Edge<T>> path){
public void add(List<Edge<T>> path){
paths.add(path);
return true;
}
public List<List<Edge<T>>> get() {

View File

@@ -4,4 +4,4 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p: %d{dd.MM.yyyy HH:mm:ss} (%F:%L) - %m%n
#log4j.logger.ru.trader.analysis.graph = TRACE
log4j.logger.ru.trader.analysis.VendorsGraph = DEBUG