collect more info on check powerplay intersects
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package ru.trader.controllers;
|
package ru.trader.controllers;
|
||||||
|
|
||||||
|
import javafx.beans.property.*;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
@@ -11,6 +12,7 @@ import ru.trader.model.*;
|
|||||||
import ru.trader.model.support.BindingsHelper;
|
import ru.trader.model.support.BindingsHelper;
|
||||||
import ru.trader.view.support.PowerStateStringConverter;
|
import ru.trader.view.support.PowerStateStringConverter;
|
||||||
import ru.trader.view.support.PowerStringConverter;
|
import ru.trader.view.support.PowerStringConverter;
|
||||||
|
import ru.trader.view.support.ViewUtils;
|
||||||
import ru.trader.view.support.autocomplete.AutoCompletion;
|
import ru.trader.view.support.autocomplete.AutoCompletion;
|
||||||
import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
|
import ru.trader.view.support.autocomplete.CachedSuggestionProvider;
|
||||||
import ru.trader.view.support.autocomplete.SystemsProvider;
|
import ru.trader.view.support.autocomplete.SystemsProvider;
|
||||||
@@ -45,12 +47,12 @@ public class PowerPlayController {
|
|||||||
@FXML
|
@FXML
|
||||||
private ListView<SystemModel> controlSystems;
|
private ListView<SystemModel> controlSystems;
|
||||||
@FXML
|
@FXML
|
||||||
private TableView<SystemModel> tblResults;
|
private TableView<ResultEntry> tblResults;
|
||||||
|
|
||||||
private MarketModel world;
|
private MarketModel world;
|
||||||
private ProfileModel profile;
|
private ProfileModel profile;
|
||||||
private PowerPlayAnalyzator analyzator;
|
private PowerPlayAnalyzator analyzator;
|
||||||
private final List<SystemModel> result = FXCollections.observableArrayList();
|
private final List<ResultEntry> result = FXCollections.observableArrayList();
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -98,17 +100,17 @@ public class PowerPlayController {
|
|||||||
Collection<Place> controlls = getControlSystems();
|
Collection<Place> controlls = getControlSystems();
|
||||||
result.clear();
|
result.clear();
|
||||||
if (starSystem != null && !controlls.isEmpty()){
|
if (starSystem != null && !controlls.isEmpty()){
|
||||||
Collection<Place> intersects = analyzator.getIntersects(starSystem, controlls);
|
Collection<PowerPlayAnalyzator.IntersectData> intersects = analyzator.getIntersects(starSystem, controlls);
|
||||||
result.addAll(BindingsHelper.observableList(intersects, world.getModeler()::get));
|
result.addAll(BindingsHelper.observableList(intersects, d -> new ResultEntry(d, starSystem)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getControlling(){
|
private void getControlling(){
|
||||||
Place starSystem = ModelFabric.get(checkedSystem.getValue());
|
final Place starSystem = ModelFabric.get(checkedSystem.getValue());
|
||||||
result.clear();
|
result.clear();
|
||||||
if (starSystem != null){
|
if (starSystem != null){
|
||||||
Collection<Place> controllings = analyzator.getControlling(starSystem);
|
Collection<PowerPlayAnalyzator.IntersectData> controllings = analyzator.getControlling(starSystem);
|
||||||
result.addAll(BindingsHelper.observableList(controllings, world.getModeler()::get));
|
result.addAll(BindingsHelper.observableList(controllings,d -> new ResultEntry(d, starSystem)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,8 +118,17 @@ public class PowerPlayController {
|
|||||||
Collection<Place> controlls = getControlSystems();
|
Collection<Place> controlls = getControlSystems();
|
||||||
result.clear();
|
result.clear();
|
||||||
if (!controlls.isEmpty()){
|
if (!controlls.isEmpty()){
|
||||||
Collection<Place> near = analyzator.getNear(controlls);
|
Collection<PowerPlayAnalyzator.IntersectData> near = analyzator.getNear(controlls);
|
||||||
result.addAll(BindingsHelper.observableList(near, world.getModeler()::get));
|
result.addAll(BindingsHelper.observableList(near, ResultEntry::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getNearExpansions(){
|
||||||
|
Collection<Place> controlls = getControlSystems();
|
||||||
|
result.clear();
|
||||||
|
if (!controlls.isEmpty()){
|
||||||
|
Collection<PowerPlayAnalyzator.IntersectData> near = analyzator.getNearExpansions(controlls);
|
||||||
|
result.addAll(BindingsHelper.observableList(near, ResultEntry::new));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +159,9 @@ public class PowerPlayController {
|
|||||||
if (rbNear.isSelected()){
|
if (rbNear.isSelected()){
|
||||||
getNear();
|
getNear();
|
||||||
}
|
}
|
||||||
|
if (rbExpansions.isSelected()){
|
||||||
|
getNearExpansions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -184,10 +197,83 @@ public class PowerPlayController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void copyToClipboard(){
|
private void copyToClipboard(){
|
||||||
SystemModel starSystem = tblResults.getSelectionModel().getSelectedItem();
|
ResultEntry entry = tblResults.getSelectionModel().getSelectedItem();
|
||||||
if (starSystem != null){
|
if (entry != null){
|
||||||
Main.copyToClipboard(starSystem.getName());
|
Main.copyToClipboard(entry.starSystem.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class ResultEntry {
|
||||||
|
private final SystemModel starSystem;
|
||||||
|
private final StationModel nearStation;
|
||||||
|
private final ReadOnlyDoubleProperty distance;
|
||||||
|
private final ReadOnlyStringProperty maxSizePad;
|
||||||
|
private final ReadOnlyIntegerProperty intersectCount;
|
||||||
|
private final ReadOnlyStringProperty controlling;
|
||||||
|
|
||||||
|
public ResultEntry(PowerPlayAnalyzator.IntersectData data) {
|
||||||
|
this(data, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultEntry(PowerPlayAnalyzator.IntersectData data, Place from) {
|
||||||
|
starSystem = world.getModeler().get(data.getStarSystem());
|
||||||
|
maxSizePad = new SimpleStringProperty(starSystem.getMaxSizePad());
|
||||||
|
intersectCount = new SimpleIntegerProperty(data.getCount());
|
||||||
|
nearStation = starSystem.getNear();
|
||||||
|
controlling = new SimpleStringProperty(getControllingString(data.getControllingSystems()));
|
||||||
|
distance = new SimpleDoubleProperty(from != null ? from.getDistance(data.getStarSystem()) : Double.NaN);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getControllingString(Collection<PowerPlayAnalyzator.ControllingData> controllings) {
|
||||||
|
StringBuilder res = new StringBuilder();
|
||||||
|
for (PowerPlayAnalyzator.ControllingData data : controllings) {
|
||||||
|
if (res.length() != 0) res.append("\n");
|
||||||
|
res.append(data.getCenter().getName());
|
||||||
|
res.append(" (").append(ViewUtils.distanceToString(data.getDistance())).append(")");
|
||||||
|
}
|
||||||
|
return res.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ReadOnlyStringProperty stationProperty(){
|
||||||
|
return new SimpleStringProperty(String.format("%s (%.0f Ls)", nearStation.getName(), nearStation.getDistance()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyStringProperty nameProperty(){
|
||||||
|
return starSystem.nameProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GOVERNMENT getGovernment() {
|
||||||
|
return starSystem.getGovernment();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FACTION getFaction() {
|
||||||
|
return starSystem.getFaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public POWER getPower() {
|
||||||
|
return starSystem.getPower();
|
||||||
|
}
|
||||||
|
|
||||||
|
public POWER_STATE getPowerState() {
|
||||||
|
return starSystem.getPowerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyDoubleProperty distanceProperty() {
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyStringProperty maxSizePadProperty() {
|
||||||
|
return maxSizePad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyIntegerProperty intersectCountProperty() {
|
||||||
|
return intersectCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyStringProperty controllingProperty() {
|
||||||
|
return controlling;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import ru.trader.core.*;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SystemModel {
|
public class SystemModel {
|
||||||
@@ -167,6 +168,24 @@ public class SystemModel {
|
|||||||
&& (system.getFaction() == FACTION.NONE || !system.isEmpty());
|
&& (system.getFaction() == FACTION.NONE || !system.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMaxSizePad(){
|
||||||
|
if (system.isEmpty()) return "-";
|
||||||
|
String size = "M";
|
||||||
|
for (Vendor vendor : system.get()) {
|
||||||
|
STATION_TYPE type = vendor.getType();
|
||||||
|
if (type != null){
|
||||||
|
if (type.hasLargeLandpad()) return "L";
|
||||||
|
} else {
|
||||||
|
size = "?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StationModel getNear(){
|
||||||
|
Optional<Vendor> near = system.get().stream().sorted((v1, v2) -> Double.compare(v1.getDistance(), v2.getDistance())).findFirst();
|
||||||
|
return asModel(near.orElse(null));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -74,9 +74,18 @@
|
|||||||
</TableColumn>
|
</TableColumn>
|
||||||
<TableColumn minWidth="110" text="%market.order.distance" fx:id="sortColumn" sortType="ASCENDING">
|
<TableColumn minWidth="110" text="%market.order.distance" fx:id="sortColumn" sortType="ASCENDING">
|
||||||
<cellFactory><DistanceCell /></cellFactory>
|
<cellFactory><DistanceCell /></cellFactory>
|
||||||
|
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
|
||||||
</TableColumn>
|
</TableColumn>
|
||||||
<TableColumn minWidth="80" text="Типы площадок">
|
<TableColumn minWidth="80" text="Тип площадки">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="maxSizePad"/></cellValueFactory>
|
||||||
</TableColumn>
|
</TableColumn>
|
||||||
|
<TableColumn minWidth="80" text="Пересечений">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="intersectCount"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn minWidth="200" text="Контролируемые системы">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="controlling"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
|
||||||
</columns>
|
</columns>
|
||||||
<columnResizePolicy>
|
<columnResizePolicy>
|
||||||
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
package ru.trader.analysis;
|
package ru.trader.analysis;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.core.Market;
|
import ru.trader.core.*;
|
||||||
import ru.trader.core.POWER;
|
|
||||||
import ru.trader.core.Place;
|
|
||||||
import ru.trader.core.StarSystemFilter;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Comparator;
|
import java.util.function.Function;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -33,59 +30,95 @@ public class PowerPlayAnalyzator {
|
|||||||
this.starSystemFilter = starSystemFilter;
|
this.starSystemFilter = starSystemFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Place> getControlling(Place starSystem){
|
public Collection<IntersectData> getControlling(Place starSystem){
|
||||||
return getControlling(starSystem, market.get(), CONTROLLING_RADIUS);
|
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
||||||
|
return getControlling(starSystem, candidates, CONTROLLING_RADIUS).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Place> getIntersects(Collection<Place> starSystems){
|
public Collection<IntersectData> getIntersects(Collection<Place> starSystems){
|
||||||
return getIntersects(market.get(), starSystems, CONTROLLING_RADIUS);
|
return getIntersects(market.get(), starSystems, CONTROLLING_RADIUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Place> getIntersects(Place starSystem, Collection<Place> starSystems){
|
public Collection<IntersectData> getIntersects(Place starSystem, Collection<Place> starSystems){
|
||||||
return getIntersects(starSystem, market.get(), starSystems, CONTROLLING_RADIUS);
|
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
||||||
|
return getIntersects(starSystem, candidates, starSystems, CONTROLLING_RADIUS).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Place> getNear(Collection<Place> starSystems){
|
public Collection<IntersectData> getNear(Collection<Place> starSystems){
|
||||||
Stream<Place> candidates = market.get().stream().filter(p -> p.getPower() == POWER.NONE);
|
Stream<Place> candidates = market.get().stream().filter(p -> p.getPower() == POWER.NONE && p.getFaction() != FACTION.NONE);
|
||||||
return getNear(candidates, starSystems, CONTROLLING_RADIUS, CONTROLLING_RADIUS*2);
|
return getNear(candidates, starSystems, CONTROLLING_RADIUS, CONTROLLING_RADIUS*2).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<Place> getControlling(Place starSystem, Collection<Place> starSystems, double radius){
|
public Collection<IntersectData> getNearExpansions(Collection<Place> starSystems){
|
||||||
return starSystems.stream()
|
return getNearExpansions(market.get(), starSystems, CONTROLLING_RADIUS * 2);
|
||||||
.filter(new Controlling(starSystem, radius))
|
}
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
public static Collection<IntersectData> getControlling(Place starSystem, Collection<Place> starSystems, double radius){
|
||||||
|
return getControlling(starSystem, starSystems.stream(), radius).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<IntersectData> getControlling(Place starSystem, Stream<Place> starSystems, double radius){
|
||||||
|
IntersectsMapper controllingMapper = new IntersectsMapper(Collections.singleton(starSystem), radius, true, true);
|
||||||
|
return starSystems
|
||||||
|
.map(controllingMapper)
|
||||||
|
.filter(IntersectData::isIntersect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Collection<Place> getNear(Collection<Place> starSystems, Collection<Place> centers, double radius, double maxDistance){
|
public static Collection<IntersectData> getNear(Collection<Place> starSystems, Collection<Place> centers, double radius, double maxDistance){
|
||||||
return starSystems.stream()
|
return getNear(starSystems.stream(), centers, radius, maxDistance).collect(Collectors.toList());
|
||||||
.filter(new FarDropper(centers, maxDistance))
|
|
||||||
.filter(intersectsAnyPredicate(centers, radius).negate())
|
|
||||||
.sorted(new DistanceComparator(centers))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<Place> getNear(Stream<Place> starSystems, Collection<Place> centers, double radius, double maxDistance){
|
public static Stream<IntersectData> getNear(Stream<Place> starSystems, Collection<Place> centers, double radius, double maxDistance){
|
||||||
|
IntersectsMapper controllingMapper = new IntersectsMapper(centers, radius, true, true);
|
||||||
|
IntersectsMapper distanceMapper = new IntersectsMapper(centers, maxDistance, false, true);
|
||||||
return starSystems.filter(new FarDropper(centers, maxDistance))
|
return starSystems.filter(new FarDropper(centers, maxDistance))
|
||||||
.filter(intersectsAnyPredicate(centers, radius).negate())
|
.map(controllingMapper)
|
||||||
.sorted(new DistanceComparator(centers))
|
.filter(d -> d.getCount() == 0)
|
||||||
.collect(Collectors.toList());
|
.map(d -> distanceMapper.apply(d.getStarSystem()))
|
||||||
|
.filter(IntersectData::isIntersect)
|
||||||
|
.sorted(new DistanceComparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<Place> getIntersects(Place checkedSystem, Collection<Place> starSystems, Collection<Place> centers, double radius){
|
public static Collection<IntersectData> getNearExpansions(Collection<Place> starSystems, Collection<Place> centers, double maxDistance){
|
||||||
return starSystems.stream()
|
return getNearExpansions(starSystems.stream(), centers, maxDistance).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<IntersectData> getNearExpansions(Stream<Place> starSystems, Collection<Place> centers, double maxDistance){
|
||||||
|
IntersectsMapper mapper = new IntersectsMapper(centers, maxDistance, false, true);
|
||||||
|
return starSystems.filter(new FarDropper(centers, maxDistance))
|
||||||
|
.filter(p -> p.getPowerState() == POWER_STATE.EXPANSION)
|
||||||
|
.map(mapper)
|
||||||
|
.sorted(new DistanceComparator());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Collection<IntersectData> getIntersects(Place checkedSystem, Collection<Place> starSystems, Collection<Place> centers, double radius){
|
||||||
|
return getIntersects(checkedSystem, starSystems.stream(), centers, radius).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<IntersectData> getIntersects(Place checkedSystem, Stream<Place> starSystems, Collection<Place> centers, double radius){
|
||||||
|
IntersectsMapper mapper = new IntersectsMapper(centers, radius, true, true);
|
||||||
|
return starSystems
|
||||||
.filter(new FarDropper(centers, radius))
|
.filter(new FarDropper(centers, radius))
|
||||||
.filter(intersectsPredicate(checkedSystem, centers, radius))
|
.filter(new Controlling(checkedSystem, radius))
|
||||||
.collect(Collectors.toList());
|
.map(mapper)
|
||||||
|
.filter(IntersectData::isIntersect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<Place> getIntersects(Collection<Place> starSystems, Collection<Place> centers, double radius){
|
public static Collection<IntersectData> getIntersects(Collection<Place> starSystems, Collection<Place> centers, double radius){
|
||||||
return starSystems.stream()
|
return getIntersects(starSystems.stream(), centers, radius).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<IntersectData> getIntersects(Stream<Place> starSystems, Collection<Place> centers, double radius){
|
||||||
|
IntersectsMapper mapper = new IntersectsMapper(centers, radius, false, false);
|
||||||
|
final int needCount = centers.size();
|
||||||
|
return starSystems
|
||||||
.filter(new FarDropper(centers, radius))
|
.filter(new FarDropper(centers, radius))
|
||||||
.filter(intersectsPredicate(centers, radius))
|
.map(mapper)
|
||||||
.collect(Collectors.toList());
|
.filter(d -> d.getCount() == needCount);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
private static Predicate<Place> intersectsAnyPredicate(Collection<Place> places, double radius){
|
private static Predicate<Place> intersectsAnyPredicate(Collection<Place> places, double radius){
|
||||||
Predicate<Place> intersects = null;
|
Predicate<Place> intersects = null;
|
||||||
for (Place place : places) {
|
for (Place place : places) {
|
||||||
@@ -108,7 +141,7 @@ public class PowerPlayAnalyzator {
|
|||||||
private static Predicate<Place> intersectsPredicate(Place checkedPlace, Collection<Place> places, double radius){
|
private static Predicate<Place> intersectsPredicate(Place checkedPlace, Collection<Place> places, double radius){
|
||||||
return new Controlling(checkedPlace, radius).and(intersectsAnyPredicate(places, radius));
|
return new Controlling(checkedPlace, radius).and(intersectsAnyPredicate(places, radius));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
private static class Controlling implements Predicate<Place> {
|
private static class Controlling implements Predicate<Place> {
|
||||||
private final Place center;
|
private final Place center;
|
||||||
private final double radius;
|
private final double radius;
|
||||||
@@ -178,39 +211,129 @@ public class PowerPlayAnalyzator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DistanceComparator implements Comparator<Place> {
|
private static class DistanceComparator implements Comparator<IntersectData> {
|
||||||
private final Collection<Place> centers;
|
|
||||||
private final HashMap<Place, Double> distances;
|
|
||||||
|
|
||||||
|
|
||||||
private DistanceComparator(Collection<Place> centers) {
|
private double getMinDistance(IntersectData data){
|
||||||
this.centers = centers;
|
ControllingData[] contollings = data.contollings;
|
||||||
distances = new HashMap<>(100);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getMinDistance(Place place){
|
|
||||||
Double distance = distances.get(place);
|
|
||||||
if (distance != null) return distance;
|
|
||||||
|
|
||||||
Collection<Double> ds = new LimitedQueue<>(3, Comparator.naturalOrder());
|
|
||||||
for (Place center : centers) {
|
|
||||||
double d = center.getDistance(place);
|
|
||||||
ds.add(d);
|
|
||||||
}
|
|
||||||
double dist = 0;
|
double dist = 0;
|
||||||
for (Double d : ds) {
|
int count = Math.min(3, contollings.length);
|
||||||
dist += d;
|
for (int i = 0; i < count; i++) {
|
||||||
|
dist += contollings[i].distance;
|
||||||
}
|
}
|
||||||
distances.put(place, dist);
|
return dist/count;
|
||||||
return dist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Place o1, Place o2) {
|
public int compare(IntersectData o1, IntersectData o2) {
|
||||||
return Double.compare(getMinDistance(o1), getMinDistance(o2));
|
return Double.compare(getMinDistance(o1), getMinDistance(o2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static class IntersectsMapper implements Function<Place, IntersectData> {
|
||||||
|
private final Collection<Place> centers;
|
||||||
|
private final double radius;
|
||||||
|
private final boolean findAny;
|
||||||
|
private final boolean checkedAll;
|
||||||
|
|
||||||
|
private IntersectsMapper(Collection<Place> centers, double radius, boolean findAny, boolean checkedAll) {
|
||||||
|
this.centers = new ArrayList<>(centers);
|
||||||
|
this.radius = radius;
|
||||||
|
this.findAny = findAny;
|
||||||
|
this.checkedAll = findAny || checkedAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntersectData apply(Place place) {
|
||||||
|
Collection<ControllingData> controllingDatas = null;
|
||||||
|
for (Place center : centers) {
|
||||||
|
if (place == center) continue;
|
||||||
|
double distance = center.getDistance(place);
|
||||||
|
LOG.trace("Check {}, distance to {} = {}, radius = {}", place, center, distance, radius);
|
||||||
|
if (distance <= radius){
|
||||||
|
if (findAny){
|
||||||
|
return new IntersectData(place, center, distance);
|
||||||
|
}
|
||||||
|
if (controllingDatas == null) controllingDatas = new ArrayList<>(3);
|
||||||
|
controllingDatas.add(new ControllingData(center, distance));
|
||||||
|
} else {
|
||||||
|
if (!checkedAll) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (controllingDatas == null){
|
||||||
|
return new IntersectData(place);
|
||||||
|
}
|
||||||
|
return new IntersectData(place, controllingDatas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class IntersectData {
|
||||||
|
private final Place starSystem;
|
||||||
|
private final ControllingData[] contollings;
|
||||||
|
|
||||||
|
public IntersectData(Place starSystem) {
|
||||||
|
this.starSystem = starSystem;
|
||||||
|
this.contollings = new ControllingData[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public IntersectData(Place starSystem, Place control, double distance) {
|
||||||
|
this.starSystem = starSystem;
|
||||||
|
this.contollings = new ControllingData[]{new ControllingData(control,distance)};
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntersectData(Place starSystem, Collection<ControllingData> controlling) {
|
||||||
|
this.starSystem = starSystem;
|
||||||
|
this.contollings = controlling.toArray(new ControllingData[controlling.size()]);
|
||||||
|
Arrays.sort(contollings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Place getStarSystem() {
|
||||||
|
return starSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<ControllingData> getControllingSystems(){
|
||||||
|
return Arrays.asList(contollings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount(){
|
||||||
|
return contollings.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinDistance(){
|
||||||
|
return contollings.length > 0 ? contollings[0].distance : Double.NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIntersect(){
|
||||||
|
return contollings.length > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ControllingData implements Comparable<ControllingData> {
|
||||||
|
private final Place center;
|
||||||
|
private final Double distance;
|
||||||
|
|
||||||
|
public ControllingData(Place center, Double distance) {
|
||||||
|
this.center = center;
|
||||||
|
this.distance = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Place getCenter() {
|
||||||
|
return center;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getDistance() {
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(@NotNull ControllingData o) {
|
||||||
|
Objects.requireNonNull(o, "Not compare with null");
|
||||||
|
return Double.compare(distance, o.distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ public class PowerPlayAnalyzatorTest extends Assert {
|
|||||||
Collection<Place> centers = new ArrayList<>();
|
Collection<Place> centers = new ArrayList<>();
|
||||||
centers.add(lhs3262);
|
centers.add(lhs3262);
|
||||||
|
|
||||||
Collection<Place> intersects = analyzator.getIntersects(starSystems, centers, 15);
|
Collection<PowerPlayAnalyzator.IntersectData> intersects = analyzator.getIntersects(starSystems, centers, 15);
|
||||||
LOG.info("Test intersects by LHS 3262, found {}", intersects.size());
|
LOG.info("Test intersects by LHS 3262, found {}", intersects.size());
|
||||||
for (Place intersect : intersects) {
|
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||||
assertTrue(lhs3262.getDistance(intersect) <= 15);
|
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 15);
|
||||||
}
|
}
|
||||||
assertTrue(intersects.containsAll(controllingLhs3262));
|
assertTrue(intersects.containsAll(controllingLhs3262));
|
||||||
assertEquals(controllingLhs3262.size(), intersects.size());
|
assertEquals(controllingLhs3262.size(), intersects.size());
|
||||||
@@ -58,30 +58,30 @@ public class PowerPlayAnalyzatorTest extends Assert {
|
|||||||
centers.add(aulin);
|
centers.add(aulin);
|
||||||
intersects = analyzator.getIntersects(starSystems, centers, 15);
|
intersects = analyzator.getIntersects(starSystems, centers, 15);
|
||||||
LOG.info("Test intersects by LHS 3262 and Aulin, found {}", intersects.size());
|
LOG.info("Test intersects by LHS 3262 and Aulin, found {}", intersects.size());
|
||||||
for (Place intersect : intersects) {
|
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||||
assertTrue(lhs3262.getDistance(intersect) <= 15);
|
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 15);
|
||||||
assertTrue(aulin.getDistance(intersect) <= 15);
|
assertTrue(aulin.getDistance(intersect.getStarSystem()) <= 15);
|
||||||
}
|
}
|
||||||
assertTrue(intersects.containsAll(expectedIntersect));
|
assertTrue(intersects.containsAll(expectedIntersect));
|
||||||
assertEquals(expectedIntersect.size(), intersects.size());
|
assertEquals(expectedIntersect.size(), intersects.size());
|
||||||
|
|
||||||
centers.add(morgor);
|
centers.add(morgor);
|
||||||
intersects = analyzator.getIntersects(starSystems, centers, 15);
|
intersects = PowerPlayAnalyzator.getIntersects(starSystems, centers, 15);
|
||||||
LOG.info("Test intersects by LHS 3262 and Aulin and Morgor, found {}", intersects.size());
|
LOG.info("Test intersects by LHS 3262 and Aulin and Morgor, found {}", intersects.size());
|
||||||
for (Place intersect : intersects) {
|
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||||
assertTrue(lhs3262.getDistance(intersect) <= 15);
|
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 15);
|
||||||
assertTrue(aulin.getDistance(intersect) <= 15);
|
assertTrue(aulin.getDistance(intersect.getStarSystem()) <= 15);
|
||||||
assertTrue(morgor.getDistance(intersect) <= 15);
|
assertTrue(morgor.getDistance(intersect.getStarSystem()) <= 15);
|
||||||
}
|
}
|
||||||
assertTrue(intersects.containsAll(expected3Intersect));
|
assertTrue(intersects.containsAll(expected3Intersect));
|
||||||
assertEquals(expected3Intersect.size(), intersects.size());
|
assertEquals(expected3Intersect.size(), intersects.size());
|
||||||
|
|
||||||
intersects = analyzator.getIntersects(starSystems, centers, 12);
|
intersects = PowerPlayAnalyzator.getIntersects(starSystems, centers, 12);
|
||||||
LOG.info("Test intersects by LHS 3262 and Aulin and Morgor, 12 radius, found {}", intersects.size());
|
LOG.info("Test intersects by LHS 3262 and Aulin and Morgor, 12 radius, found {}", intersects.size());
|
||||||
for (Place intersect : intersects) {
|
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||||
assertTrue(lhs3262.getDistance(intersect) <= 12);
|
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
assertTrue(aulin.getDistance(intersect) <= 12);
|
assertTrue(aulin.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
assertTrue(morgor.getDistance(intersect) <= 12);
|
assertTrue(morgor.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
}
|
}
|
||||||
assertEquals(0, intersects.size());
|
assertEquals(0, intersects.size());
|
||||||
|
|
||||||
@@ -102,41 +102,41 @@ public class PowerPlayAnalyzatorTest extends Assert {
|
|||||||
Collection<Place> centers = new ArrayList<>();
|
Collection<Place> centers = new ArrayList<>();
|
||||||
centers.add(lhs3262);
|
centers.add(lhs3262);
|
||||||
centers.add(aulin);
|
centers.add(aulin);
|
||||||
Collection<Place> intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12);
|
Collection<PowerPlayAnalyzator.IntersectData> intersects = PowerPlayAnalyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||||
LOG.info("Test LHS 417 intersect LHS 3262 or Aulin, found {}", intersects.size());
|
LOG.info("Test LHS 417 intersect LHS 3262 or Aulin, found {}", intersects.size());
|
||||||
for (Place intersect : intersects) {
|
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||||
assertTrue(lhs3262.getDistance(intersect) <= 12 || aulin.getDistance(intersect) <= 12);
|
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 12 || aulin.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
assertTrue(lhs417.getDistance(intersect) <= 12);
|
assertTrue(lhs417.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
}
|
}
|
||||||
assertTrue(intersects.containsAll(expectedIntersect));
|
assertTrue(intersects.containsAll(expectedIntersect));
|
||||||
assertEquals(expectedIntersect.size(), intersects.size());
|
assertEquals(expectedIntersect.size(), intersects.size());
|
||||||
|
|
||||||
centers.add(morgor);
|
centers.add(morgor);
|
||||||
intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12);
|
intersects = PowerPlayAnalyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||||
LOG.info("Test LHS 417 intersect LHS 3262 or Aulin or Morgor, found {}", intersects.size());
|
LOG.info("Test LHS 417 intersect LHS 3262 or Aulin or Morgor, found {}", intersects.size());
|
||||||
for (Place intersect : intersects) {
|
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||||
assertTrue(lhs3262.getDistance(intersect) <= 12 || aulin.getDistance(intersect) <= 12 || morgor.getDistance(intersect) <= 12);
|
assertTrue(lhs3262.getDistance(intersect.getStarSystem()) <= 12 || aulin.getDistance(intersect.getStarSystem()) <= 12 || morgor.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
assertTrue(lhs417.getDistance(intersect) <= 12);
|
assertTrue(lhs417.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
}
|
}
|
||||||
assertTrue(intersects.containsAll(expected3Intersect));
|
assertTrue(intersects.containsAll(expected3Intersect));
|
||||||
assertEquals(expected3Intersect.size(), intersects.size());
|
assertEquals(expected3Intersect.size(), intersects.size());
|
||||||
|
|
||||||
centers.clear();
|
centers.clear();
|
||||||
centers.add(morgor);
|
centers.add(morgor);
|
||||||
intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12);
|
intersects = PowerPlayAnalyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||||
LOG.info("Test LHS 417 intersect Morgor, found {}", intersects.size());
|
LOG.info("Test LHS 417 intersect Morgor, found {}", intersects.size());
|
||||||
for (Place intersect : intersects) {
|
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||||
assertTrue(morgor.getDistance(intersect) <= 12);
|
assertTrue(morgor.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
assertTrue(lhs417.getDistance(intersect) <= 12);
|
assertTrue(lhs417.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
}
|
}
|
||||||
assertEquals(0, intersects.size());
|
assertEquals(0, intersects.size());
|
||||||
|
|
||||||
centers.add(aulin);
|
centers.add(aulin);
|
||||||
intersects = analyzator.getIntersects(lhs417, starSystems, centers, 12);
|
intersects = PowerPlayAnalyzator.getIntersects(lhs417, starSystems, centers, 12);
|
||||||
LOG.info("Test LHS 417 intersect Aulin or Morgor, found {}", intersects.size());
|
LOG.info("Test LHS 417 intersect Aulin or Morgor, found {}", intersects.size());
|
||||||
for (Place intersect : intersects) {
|
for (PowerPlayAnalyzator.IntersectData intersect : intersects) {
|
||||||
assertTrue(aulin.getDistance(intersect) <= 12 || morgor.getDistance(intersect) <= 12);
|
assertTrue(aulin.getDistance(intersect.getStarSystem()) <= 12 || morgor.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
assertTrue(lhs417.getDistance(intersect) <= 12);
|
assertTrue(lhs417.getDistance(intersect.getStarSystem()) <= 12);
|
||||||
}
|
}
|
||||||
assertTrue(intersects.containsAll(expected2Intersect));
|
assertTrue(intersects.containsAll(expected2Intersect));
|
||||||
assertEquals(expected2Intersect.size(), intersects.size());
|
assertEquals(expected2Intersect.size(), intersects.size());
|
||||||
@@ -155,11 +155,11 @@ public class PowerPlayAnalyzatorTest extends Assert {
|
|||||||
Collection<Place> centers = new ArrayList<>();
|
Collection<Place> centers = new ArrayList<>();
|
||||||
centers.add(lhs3262);
|
centers.add(lhs3262);
|
||||||
centers.add(aulin);
|
centers.add(aulin);
|
||||||
Collection<Place> near = analyzator.getNear(starSystems, centers, 15, 30);
|
Collection<PowerPlayAnalyzator.IntersectData> near = PowerPlayAnalyzator.getNear(starSystems, centers, 15, 30);
|
||||||
LOG.info("Test near by LHS 3262 and Aulin, found {}", near.size());
|
LOG.info("Test near by LHS 3262 and Aulin, found {}", near.size());
|
||||||
assertTrue(near.size() > 0);
|
assertTrue(near.size() > 0);
|
||||||
for (Place place : near) {
|
for (PowerPlayAnalyzator.IntersectData place : near) {
|
||||||
Collection<Place> intersect = analyzator.getIntersects(place, starSystems, centers, 15);
|
Collection<PowerPlayAnalyzator.IntersectData> intersect = PowerPlayAnalyzator.getIntersects(place.getStarSystem(), starSystems, centers, 15);
|
||||||
assertEquals(0, intersect.size());
|
assertEquals(0, intersect.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.io.File;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PPImportTest extends Assert {
|
public class PPImportTest extends Assert {
|
||||||
|
|
||||||
@@ -42,11 +43,16 @@ public class PPImportTest extends Assert {
|
|||||||
|
|
||||||
PowerPlayAnalyzator analyzator = new PowerPlayAnalyzator(market);
|
PowerPlayAnalyzator analyzator = new PowerPlayAnalyzator(market);
|
||||||
|
|
||||||
Collection<Place> intersectsMahon = analyzator.getIntersects(Arrays.asList(opala, gd_319));
|
Collection<Place> intersectsMahon = analyzator.getIntersects(Arrays.asList(opala, gd_319))
|
||||||
Collection<Place> intersectsDuval = analyzator.getIntersects(bolg, Arrays.asList(opala, gd_319));
|
.stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList());
|
||||||
|
Collection<Place> intersectsDuval = analyzator.getIntersects(bolg, Arrays.asList(opala, gd_319))
|
||||||
|
.stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList());
|
||||||
|
|
||||||
Collection<Place> exploitedOpala = analyzator.getControlling(opala);
|
|
||||||
Collection<Place> exploitedBolg = analyzator.getControlling(bolg);
|
Collection<Place> exploitedOpala = analyzator.getControlling(opala)
|
||||||
|
.stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList());
|
||||||
|
Collection<Place> exploitedBolg = analyzator.getControlling(bolg)
|
||||||
|
.stream().map(PowerPlayAnalyzator.IntersectData::getStarSystem).collect(Collectors.toList());
|
||||||
|
|
||||||
for (Place place : intersectsMahon) {
|
for (Place place : intersectsMahon) {
|
||||||
assertEquals(POWER_STATE.EXPLOITED, place.getPowerState());
|
assertEquals(POWER_STATE.EXPLOITED, place.getPowerState());
|
||||||
|
|||||||
Reference in New Issue
Block a user