implement check station in one system on find paths
This commit is contained in:
@@ -26,10 +26,10 @@ public class MarketAnalyzerTest2 extends Assert {
|
||||
// Balance: 6000000, cargo: 440, tank: 40, distance: 13.4, jumps: 6
|
||||
// Ithaca (Palladium to LHS 3262) -> Morgor -> LHS 3006 -> LHS 3262 (Consumer Technology to Ithaca) -> LHS 3006 -> Morgor -> Ithaca
|
||||
// Profit: 981200, avg: 490600, distance: 67.5, lands: 2
|
||||
Place ithaca = market.get().stream().filter((v)->v.getName().equals("Ithaca")).findFirst().get();
|
||||
Place morgor = market.get().stream().filter((v)->v.getName().equals("Morgor")).findFirst().get();
|
||||
Place lhs3006 = market.get().stream().filter((v)->v.getName().equals("LHS 3006")).findFirst().get();
|
||||
Place lhs3262 = market.get().stream().filter((v)->v.getName().equals("LHS 3262")).findFirst().get();
|
||||
Vendor ithaca = market.get().stream().filter((v)->v.getName().equals("Ithaca")).findFirst().get().get().iterator().next();
|
||||
Vendor morgor = market.get().stream().filter((v)->v.getName().equals("Morgor")).findFirst().get().get().iterator().next();
|
||||
Vendor lhs3006 = market.get().stream().filter((v)->v.getName().equals("LHS 3006")).findFirst().get().get().iterator().next();
|
||||
Vendor lhs3262 = market.get().stream().filter((v)->v.getName().equals("LHS 3262")).findFirst().get().get().iterator().next();
|
||||
analyzer.setCargo(440);analyzer.setTank(40);analyzer.setMaxDistance(13.4);analyzer.setJumps(6);
|
||||
Collection<PathRoute> paths = analyzer.getPaths(ithaca, ithaca, 6000000);
|
||||
PathRoute expect = PathRoute.toPathRoute(ithaca, morgor, lhs3006, lhs3262, lhs3006, morgor, ithaca);
|
||||
|
||||
@@ -36,8 +36,8 @@ public class PathRouteTest extends Assert {
|
||||
v2.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM2, 350, -1));
|
||||
v2.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM3, 400, -1));
|
||||
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1.getPlace()));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2.getPlace()), false);
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2), false);
|
||||
res.finish();
|
||||
res.sort(10000, 5);
|
||||
return res.getRoot();
|
||||
@@ -77,9 +77,9 @@ public class PathRouteTest extends Assert {
|
||||
v3.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM2, 350, -1));
|
||||
v3.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM3, 400, -1));
|
||||
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1.getPlace()));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3.getPlace()), false);
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3), false);
|
||||
res.finish();
|
||||
res.sort(10000, 5);
|
||||
return res.getRoot();
|
||||
@@ -129,10 +129,10 @@ public class PathRouteTest extends Assert {
|
||||
v3.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM1, 200, -1));
|
||||
v4.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM3, 450, -1));
|
||||
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1.getPlace()));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v4.getPlace()), false);
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v4), false);
|
||||
res.finish();
|
||||
res.sort(10000, 5);
|
||||
return res.getRoot();
|
||||
@@ -193,11 +193,11 @@ public class PathRouteTest extends Assert {
|
||||
v4.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM3, 370, -1));
|
||||
v5.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM1, 400, -1));
|
||||
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1.getPlace()));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v4.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v5.getPlace()), false);
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v4), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v5), false);
|
||||
res.finish();
|
||||
res.sort(10000, 5);
|
||||
return res.getRoot();
|
||||
@@ -265,10 +265,10 @@ public class PathRouteTest extends Assert {
|
||||
v3.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM1, 200, -1));
|
||||
v4.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM3, 450, -1));
|
||||
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1.getPlace()));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v4.getPlace()), false);
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v4), false);
|
||||
res.finish();
|
||||
res.sort(500, 5);
|
||||
return res.getRoot();
|
||||
@@ -325,8 +325,8 @@ public class PathRouteTest extends Assert {
|
||||
|
||||
v2.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM2, 225, -1));
|
||||
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1.getPlace()));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2.getPlace()), false);
|
||||
PathRoute res = new PathRoute(new Vertex<>(v1));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v2), false);
|
||||
res.finish();
|
||||
res.sort(500, 5);
|
||||
return res.getRoot();
|
||||
@@ -342,9 +342,9 @@ public class PathRouteTest extends Assert {
|
||||
v3.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM1, 200, -1));
|
||||
v4.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM3, 450, -1));
|
||||
|
||||
PathRoute res = new PathRoute(new Vertex<>(v2.getPlace()));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3.getPlace()), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v4.getPlace()), false);
|
||||
PathRoute res = new PathRoute(new Vertex<>(v2));
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v3), false);
|
||||
res = (PathRoute) res.connectTo(new Vertex<>(v4), false);
|
||||
res.finish();
|
||||
res.sort(500, 5);
|
||||
return res.getRoot();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package ru.trader.graph;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Point implements Connectable<Point> {
|
||||
private int x;
|
||||
private String name;
|
||||
@@ -42,4 +46,11 @@ public class Point implements Connectable<Point> {
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Connectable<Point> o) {
|
||||
Objects.requireNonNull(o, "Not compare with null");
|
||||
Point other =(Point)o;
|
||||
return Integer.compare(hashCode(), other.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,19 @@ public class RouteGraphTest extends Assert {
|
||||
private final static Item ITEM1 = new SimpleItem("ITEM1");
|
||||
private final static Item ITEM2 = new SimpleItem("ITEM2");
|
||||
private final static Item ITEM3 = new SimpleItem("ITEM3");
|
||||
private final static Item ITEM4 = new SimpleItem("ITEM4");
|
||||
private final static Item ITEM5 = new SimpleItem("ITEM5");
|
||||
private static Vendor v1;
|
||||
private static Vendor v2;
|
||||
private static Vendor v3;
|
||||
private static Vendor v4;
|
||||
private static Vendor v5;
|
||||
private static Vendor v6;
|
||||
private static Place p1;
|
||||
private static Place p2;
|
||||
private static Place p3;
|
||||
private static Place p4;
|
||||
private static Place p5;
|
||||
|
||||
|
||||
static {
|
||||
@@ -30,11 +35,14 @@ public class RouteGraphTest extends Assert {
|
||||
p2 = new SimplePlace("v2");
|
||||
p3 = new SimplePlace("v3");
|
||||
p4 = new SimplePlace("v4");
|
||||
p5 = new SimplePlace("p5",5,5,5);
|
||||
|
||||
v1 = new SimpleVendor("v1");
|
||||
v2 = new SimpleVendor("v2");
|
||||
v3 = new SimpleVendor("v3");
|
||||
v4 = new SimpleVendor("v4");
|
||||
v5 = new SimpleVendor("v5");
|
||||
v6 = new SimpleVendor("v6");
|
||||
|
||||
v1.add(new SimpleOffer(OFFER_TYPE.SELL, ITEM1, 100, -1));
|
||||
v1.add(new SimpleOffer(OFFER_TYPE.SELL, ITEM2, 200, -1));
|
||||
@@ -42,24 +50,28 @@ public class RouteGraphTest extends Assert {
|
||||
v2.add(new SimpleOffer(OFFER_TYPE.SELL, ITEM1, 150, -1));
|
||||
v2.add(new SimpleOffer(OFFER_TYPE.SELL, ITEM3, 320, -1));
|
||||
v3.add(new SimpleOffer(OFFER_TYPE.SELL, ITEM3, 390, -1));
|
||||
v5.add(new SimpleOffer(OFFER_TYPE.SELL, ITEM4, 100, -1));
|
||||
v6.add(new SimpleOffer(OFFER_TYPE.SELL, ITEM5, 100, -1));
|
||||
|
||||
v2.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM2, 225, -1));
|
||||
v3.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM1, 200, -1));
|
||||
v4.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM3, 450, -1));
|
||||
v5.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM5, 500, -1));
|
||||
v6.add(new SimpleOffer(OFFER_TYPE.BUY, ITEM4, 500, -1));
|
||||
|
||||
p1.add(v1);p2.add(v2);p3.add(v3);p4.add(v4);
|
||||
market.add(p1);market.add(p2);market.add(p3);market.add(p4);
|
||||
p1.add(v1);p2.add(v2);p3.add(v3);p4.add(v4);p5.add(v5);p5.add(v6);
|
||||
market.add(p1);market.add(p2);market.add(p3);market.add(p4);market.add(p5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoutes() throws Exception {
|
||||
RouteGraph graph = new RouteGraph(p1, market.get(), 1, 1, true, 4);
|
||||
RouteGraph graph = new RouteGraph(v1, market.getVendors(), 1, 1, true, 4);
|
||||
graph.setBalance(500);
|
||||
graph.setCargo(5);
|
||||
//Profit: 150 180 200 230 670 620 950 890 620 950 1015 1180 890 950 930
|
||||
//Landings: 1 2 3 4 4 2 3 3 2 3 4 4 3 3 4
|
||||
//Prof: 150 90 66.66 57.5 167.5 310 316.66 296.66 310 316.66 253.75 295 296.66 316.66 232.5
|
||||
ArrayList<Path<Place>> routes = (ArrayList<Path<Place>>) graph.getPathsTo(p4, 5);
|
||||
ArrayList<Path<Vendor>> routes = (ArrayList<Path<Vendor>>) graph.getPathsTo(v4, 5);
|
||||
assertEquals(5, routes.size());
|
||||
|
||||
PathRoute path = (PathRoute) routes.get(0).getRoot();
|
||||
@@ -82,4 +94,20 @@ public class RouteGraphTest extends Assert {
|
||||
assertEquals(620, path.getProfit(), 0.001);
|
||||
assertEquals(2, path.getLandsCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoutes2() throws Exception {
|
||||
RouteGraph graph = new RouteGraph(v5, market.getVendors(), 1, 15, true, 4);
|
||||
graph.setBalance(500);
|
||||
graph.setCargo(5);
|
||||
ArrayList<Path<Vendor>> routes = (ArrayList<Path<Vendor>>) graph.getPathsTo(v1, 5);
|
||||
assertEquals(5, routes.size());
|
||||
|
||||
//v5 -> v6 -> v5 -> v6 -> v1
|
||||
PathRoute path = (PathRoute) routes.get(0).getRoot();
|
||||
assertEquals(6000, path.getProfit(), 0.001);
|
||||
assertEquals(4, path.getLandsCount());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,18 +25,18 @@ public class RouteSearcherTest extends Assert {
|
||||
// Balance: 6000000, cargo: 440, tank: 40, distance: 13.4, jumps: 6
|
||||
// Ithaca (Palladium to LHS 3262) -> Morgor -> LHS 3006 -> LHS 3262 (Consumer Technology to Ithaca) -> LHS 3006 -> Morgor -> Ithaca
|
||||
// Profit: 981200, avg: 490600, distance: 67.5, lands: 2
|
||||
Place ithaca = market.get().stream().filter((v)->v.getName().equals("Ithaca")).findFirst().get();
|
||||
Vendor ithaca = market.get().stream().filter((v)->v.getName().equals("Ithaca")).findFirst().get().get().iterator().next();
|
||||
|
||||
RouteSearcher searcher = new RouteSearcher(13.4, 40);
|
||||
RouteGraph graph = new RouteGraph(ithaca, market.get(), 40, 13.4, true, 6);
|
||||
RouteGraph graph = new RouteGraph(ithaca, market.getVendors(), 40, 13.4, true, 6);
|
||||
graph.setCargo(440);
|
||||
graph.setBalance(6000000);
|
||||
|
||||
|
||||
List<Path<Place>> epaths = graph.getPathsTo(ithaca, 10);
|
||||
List<Path<Vendor>> epaths = graph.getPathsTo(ithaca, 10);
|
||||
PathRoute expect = epaths.stream().map(p -> (PathRoute) p).findFirst().get();
|
||||
|
||||
List<PathRoute> apaths = searcher.getPaths(ithaca, ithaca, market.get(), 6, 6000000, 440, 10);
|
||||
List<PathRoute> apaths = searcher.getPaths(ithaca, ithaca, market.getVendors(), 6, 6000000, 440, 10);
|
||||
PathRoute actual = apaths.stream().findFirst().get();
|
||||
assertTrue("Routes is different",expect.isRoute(actual));
|
||||
|
||||
@@ -47,27 +47,27 @@ public class RouteSearcherTest extends Assert {
|
||||
// Balance: 6000000, cargo: 440, tank: 40, distance: 13.6, jumps: 6
|
||||
// Ithaca (Palladium to LHS 3262) -> Morgor -> LHS 3006 -> LHS 3262 (Consumer Technology to Ithaca) -> LHS 3006 -> Morgor -> Ithaca
|
||||
// Profit: 981200, avg: 490600, distance: 67.5, lands: 2
|
||||
Place ithaca = market.get().stream().filter((v)->v.getName().equals("Ithaca")).findFirst().get();
|
||||
Place lhs3262 = market.get().stream().filter((v)->v.getName().equals("LHS 3262")).findFirst().get();
|
||||
Vendor ithaca = market.get().stream().filter((v)->v.getName().equals("Ithaca")).findFirst().get().get().iterator().next();
|
||||
Vendor lhs3262 = market.get().stream().filter((v)->v.getName().equals("LHS 3262")).findFirst().get().get().iterator().next();
|
||||
|
||||
RouteSearcher searcher = new RouteSearcher(13.6, 40);
|
||||
RouteGraph graph = new RouteGraph(ithaca, market.get(), 40, 13.6, true, 6);
|
||||
RouteGraph graph = new RouteGraph(ithaca, market.getVendors(), 40, 13.6, true, 6);
|
||||
graph.setCargo(440);
|
||||
graph.setBalance(6000000);
|
||||
|
||||
List<Path<Place>> epaths = graph.getPathsTo(ithaca, 10);
|
||||
List<Path<Vendor>> epaths = graph.getPathsTo(ithaca, 10);
|
||||
PathRoute expect = epaths.stream().map(p -> (PathRoute) p).findFirst().get();
|
||||
|
||||
List<PathRoute> apaths = searcher.getPaths(ithaca, ithaca, market.get(), 6, 6000000, 440, 10);
|
||||
List<PathRoute> apaths = searcher.getPaths(ithaca, ithaca, market.getVendors(), 6, 6000000, 440, 10);
|
||||
PathRoute actual = apaths.stream().findFirst().get();
|
||||
assertTrue("Routes is different",expect.isRoute(actual));
|
||||
|
||||
graph = new RouteGraph(lhs3262, market.get(), 40, 13.6, true, 6);
|
||||
graph = new RouteGraph(lhs3262, market.getVendors(), 40, 13.6, true, 6);
|
||||
graph.setCargo(440);
|
||||
graph.setBalance(6000000);
|
||||
|
||||
expect = graph.getPathsTo(lhs3262, 10).stream().map(p -> (PathRoute)p).findFirst().get();
|
||||
apaths = searcher.getPaths(lhs3262, lhs3262, market.get(), 6, 6000000, 440, 10);
|
||||
apaths = searcher.getPaths(lhs3262, lhs3262, market.getVendors(), 6, 6000000, 440, 10);
|
||||
actual = apaths.stream().findFirst().get();
|
||||
assertEquals("Routes is different",expect.getAvgProfit(), actual.getAvgProfit(), 0.00001);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user