Archived
0

implement recompute, refresh path, add station to path

This commit is contained in:
iMoHax
2015-01-16 13:11:36 +03:00
parent 04957e5a86
commit 4b0c2f0a0e
13 changed files with 221 additions and 49 deletions

View File

@@ -1,7 +1,6 @@
package ru.trader.controllers;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
@@ -35,6 +34,9 @@ public class RouterController {
@FXML
private ScrollPane path;
@FXML
private Button addBtn;
@FXML
private Button editBtn;
@@ -117,6 +119,11 @@ public class RouterController {
distance.setValue(Main.SETTINGS.getDistance());
jumps.setValue(Main.SETTINGS.getJumps());
addBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> {
StationModel st = tStation.getValue();
return st == null || st == ModelFabric.NONE_STATION;
}, tStation.valueProperty()));
editBtn.disableProperty().bind(tblOrders.getSelectionModel().selectedIndexProperty().isEqualTo(-1));
removeBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> {
int sel = tblOrders.getSelectionModel().getSelectedIndex();
@@ -155,6 +162,7 @@ public class RouterController {
totalBalance.add(order.getProfit());
source.setValue(order.getBuyer().getSystem());
sStation.setValue(order.getBuyer());
target.setValue(ModelFabric.NONE_SYSTEM);
balance.setDisable(true);
}
@@ -163,12 +171,27 @@ public class RouterController {
totalBalance.sub(order.getProfit());
source.setValue(order.getSystem());
sStation.setValue(order.getStation());
target.setValue(ModelFabric.NONE_SYSTEM);
if (orders.isEmpty()) {
balance.setDisable(false);
source.setDisable(false);
}
}
public void addStationToRoute(){
StationModel sS = sStation.getValue();
StationModel tS = tStation.getValue();
PathRouteModel r = market.getPath(sS, tS);
if (route != null){
route = route.add(r);
} else {
route = r;
}
refreshPath();
source.setValue(tS.getSystem());
sStation.setValue(tS);
}
public void editOrders(){
OrderModel sel = tblOrders.getSelectionModel().getSelectedItem();
int index = tblOrders.getSelectionModel().getSelectedIndex();
@@ -195,6 +218,29 @@ public class RouterController {
}
}
public void recompute(){
if (route != null){
route.recompute(balance.getValue().doubleValue(), cargo.getValue().longValue());
orders.clear();
orders.addAll(route.getOrders());
refreshPath();
}
}
public void rebuild(){
if (route != null){
PathRouteModel r = market.getRoute(route, balance.getValue().doubleValue());
if (r != null){
route = r;
orders.clear();
orders.addAll(route.getOrders());
refreshPath();
} else {
recompute();
}
}
}
public void removeAll(){
orders.clear();
totalBalance.setValue(balance.getValue());
@@ -256,14 +302,14 @@ public class RouterController {
if (this.route == null){
this.route = route;
} else {
this.route.add(route.getPath());
this.route = this.route.add(route);
}
refreshPath();
}
private void addOrderToPath(OrderModel order){
if (route != null){
route.add(order);
route = route.add(order);
} else {
route = market.getPath(order);
}

View File

@@ -20,8 +20,6 @@ import ru.trader.services.OrdersSearchTask;
import ru.trader.services.RoutesSearchTask;
import ru.trader.view.support.Localization;
import java.util.Collection;
import java.util.concurrent.*;
import java.util.function.Consumer;
@@ -192,10 +190,22 @@ public class MarketModel {
getRoutes(ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result);
}
PathRoute getPath(StationModel from, StationModel to) {
public PathRouteModel getRoute(PathRouteModel path, double balance) {
PathRoute p = analyzer.getPath(path.getPath().getEntries(), balance);
if (p == null) return null;
return modeler.get(p);
}
PathRoute _getPath(StationModel from, StationModel to) {
return analyzer.getPath(from.getStation(), to.getStation());
}
public PathRouteModel getPath(StationModel from, StationModel to) {
PathRoute p = analyzer.getPath(from.getStation(), to.getStation());
if (p == null) return null;
return modeler.get(p);
}
public PathRouteModel getPath(OrderModel order) {
PathRoute p = analyzer.getPath(order.getStation().getStation(), order.getBuyer().getStation());
if (p == null) return null;

View File

@@ -14,11 +14,11 @@ public class PathRouteModel {
private final int refuels;
private final int lands;
private final PathRoute path;
private final PathRoute _path;
PathRouteModel(PathRoute path, MarketModel market) {
this.market = market;
this.path = path;
this._path = path;
PathRoute p = path.getRoot();
totalProfit = p.getProfit();
lands = p.getLandsCount();
@@ -51,7 +51,7 @@ public class PathRouteModel {
}
public PathRoute getPath() {
return path;
return _path;
}
public int getLands() {
@@ -64,37 +64,48 @@ public class PathRouteModel {
public Collection<OrderModel> getOrders(){
Collection<OrderModel> res = new ArrayList<>(lands);
PathRoute p = path.getRoot();
PathRoute path = _path.getRoot();
Order cargo = null;
while (p.hasNext()){
p = p.getNext();
if (cargo == null && p.getBest()!=null){
cargo = p.getBest();
while (path.hasNext()){
path = path.getNext();
if (cargo == null && path.getBest()!=null){
cargo = path.getBest();
OrderModel order = market.getModeler().get(cargo);
order.setPath(p);
order.setPath(path);
res.add(order);
}
if (cargo!=null && cargo.isBuyer(p.get())){
if (cargo!=null && cargo.isBuyer(path.get())){
cargo = null;
}
}
return res;
}
public void add(OrderModel order){
PathRoute p = market.getPath(order.getStation(), order.getBuyer());
if (p == null) return;
p.getRoot().getNext().setOrder(new Order(order.getOffer().getOffer(), order.getBuyOffer().getOffer(), order.getCount()));
PathRoute head = path.getEnd();
add(p);
order.setPath(head);
PathRoute _add(PathRoute route){
return _path.add(route, true);
}
public void add(PathRoute route){
path.getEnd().add(route, true);
public PathRouteModel add(OrderModel order){
PathRoute path = market._getPath(order.getStation(), order.getBuyer());
if (path == null) return this;
path.getRoot().getNext().setOrder(new Order(order.getOffer().getOffer(), order.getBuyOffer().getOffer(), order.getCount()));
PathRoute head = _path.getEnd();
PathRouteModel res = new PathRouteModel(_add(path), market);
order.setPath(head);
return res;
}
public PathRouteModel add(PathRouteModel route){
return new PathRouteModel(_add(route.getPath()), market);
}
public PathRouteModel remove(OrderModel order) {
return new PathRouteModel(path.dropTo(order.getStation().getStation()), market);
return new PathRouteModel(_path.dropTo(order.getStation().getStation()), market);
}
public void recompute(double balance, long cargo) {
_path.refresh();
_path.sort(balance, cargo);
}
}

View File

@@ -38,6 +38,7 @@ routes.lands=Landings
# Dialog
dialog.confirm.save=Changes were not saved, save changes?
dialog.confirm.remove=Are you sure you want to delete %s?
dialog.button.add=Add
dialog.button.save=Save
dialog.button.edit=Edit
dialog.button.remove=Remove
@@ -115,6 +116,8 @@ router.pane.route=Route parameters
router.pane.route.from=From:
router.pane.route.to=To:
router.pane.route.jumps=Jumps:
router.button.recompute=Recompute
router.button.rebuild=Rebuild
router.button.top=TOP 100
router.pane.total=Total
router.pane.total.profit=Profit:

View File

@@ -38,6 +38,7 @@ routes.lands=\u041F\u043E\u0441\u0430\u0434\u043E\u043A
# Dialog
dialog.confirm.save=\u0418\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u044F \u043D\u0435 \u0431\u044B\u043B\u0438 \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u044B, \u0441\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C?
dialog.confirm.remove=\u0412\u044B \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043B\u044C\u043D\u043E \u0445\u043E\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043B\u0438\u0442\u044C %s?
dialog.button.add=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C
dialog.button.save=\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C
dialog.button.edit=\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C
dialog.button.remove=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
@@ -115,6 +116,8 @@ router.pane.route=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u043C\
router.pane.route.from=\u041E\u0442:
router.pane.route.to=\u0414\u043E:
router.pane.route.jumps=\u041F\u0440\u044B\u0436\u043A\u043E\u0432:
router.button.recompute=\u041F\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u0430\u0442\u044C
router.button.rebuild=\u041F\u0435\u0440\u0435\u0441\u0442\u0440\u043E\u0438\u0442\u044C
router.button.top=TOP 100
router.pane.total=\u0418\u0442\u043E\u0433\u043E
router.pane.total.profit=\u041F\u0440\u0438\u0431\u044B\u043B\u044C:

View File

@@ -10,35 +10,35 @@
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="ru.trader.controllers.ItemsController">
<TableView fx:id="tblItems" editable="true" VBox.vgrow="ALWAYS" prefWidth="1175.0">
<TableView fx:id="tblItems" editable="true" VBox.vgrow="ALWAYS" prefWidth="1195.0">
<columns>
<TableColumn editable="true" minWidth="200.0" text="%market.item.name">
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
</TableColumn>
<TableColumn editable="true" resizable="false" text="%market.offer.buy">
<columns>
<TableColumn minWidth="140.0" text="%market.offer.min">
<TableColumn minWidth="145.0" text="%market.offer.min">
<cellValueFactory><OfferCellValueImpl property="minSell"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="80.0" text="%market.offer.avg">
<cellFactory><DoubleCell/></cellFactory>
<cellValueFactory><PropertyValueFactory property="avgSell"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="140.0" text="%market.offer.max">
<TableColumn minWidth="145.0" text="%market.offer.max">
<cellValueFactory><OfferCellValueImpl property="maxSell"/></cellValueFactory>
</TableColumn>
</columns>
</TableColumn>
<TableColumn editable="true" resizable="false" text="%market.offer.sell">
<columns>
<TableColumn minWidth="140.0" text="%market.offer.min">
<TableColumn minWidth="145.0" text="%market.offer.min">
<cellValueFactory><OfferCellValueImpl property="minBuy"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="80.0" text="%market.offer.avg">
<cellFactory><DoubleCell/></cellFactory>
<cellValueFactory><PropertyValueFactory property="avgBuy"/></cellValueFactory>
</TableColumn>
<TableColumn minWidth="140.0" text="%market.offer.max">
<TableColumn minWidth="145.0" text="%market.offer.max">
<cellValueFactory><OfferCellValueImpl property="maxBuy"/></cellValueFactory>
</TableColumn>
</columns>

View File

@@ -18,11 +18,11 @@
<fx:define><Insets fx:id="stationsPadding" left="12" right="10" /></fx:define>
<columnConstraints>
<ColumnConstraints minWidth="250" maxWidth="250"/>
<ColumnConstraints minWidth="270" maxWidth="270"/>
<ColumnConstraints fillWidth="true"/>
</columnConstraints>
<TitledPane GridPane.rowSpan="3" text="%market.systems" minWidth="250" prefHeight="570" collapsible="false">
<TitledPane GridPane.rowSpan="3" text="%market.systems" minWidth="270" prefHeight="590" collapsible="false">
<ListView fx:id="systems">
<contextMenu>
<ContextMenu>

View File

@@ -15,12 +15,12 @@
<fx:define><Insets fx:id="fields_group_margin" left="2" right="10"/></fx:define>
<fx:define><Insets fx:id="separator_margin" top="10" bottom="10"/></fx:define>
<VBox minWidth="250">
<VBox minWidth="270">
<TitledPane text="%router.pane.ship" minHeight="160" collapsible="false">
<GridPane vgap="4">
<columnConstraints>
<ColumnConstraints minWidth="140" />
<ColumnConstraints minWidth="90" maxWidth="90"/>
<ColumnConstraints minWidth="150" />
<ColumnConstraints minWidth="100" maxWidth="100"/>
</columnConstraints>
<Label text="%router.pane.ship.balance"/>
<NumberField fx:id="balance" GridPane.columnIndex="1" />
@@ -32,26 +32,31 @@
<NumberField fx:id="distance" GridPane.columnIndex="1" GridPane.rowIndex="3" />
</GridPane>
</TitledPane>
<TitledPane text="%router.pane.route" minHeight="250" collapsible="false">
<TitledPane text="%router.pane.route" minHeight="320" collapsible="false">
<GridPane vgap="4">
<columnConstraints>
<ColumnConstraints minWidth="70"/>
<ColumnConstraints minWidth="160" maxWidth="160"/>
<ColumnConstraints minWidth="80"/>
<ColumnConstraints minWidth="170" maxWidth="170"/>
</columnConstraints>
<Label text="%router.pane.route.from" />
<ComboBox fx:id="source" prefWidth="160" GridPane.columnIndex="1" />
<ComboBox fx:id="sStation" prefWidth="160" GridPane.rowIndex="1" GridPane.columnIndex="1" />
<ComboBox fx:id="source" prefWidth="170" GridPane.columnIndex="1" />
<ComboBox fx:id="sStation" prefWidth="170" GridPane.rowIndex="1" GridPane.columnIndex="1" />
<Label text="%router.pane.route.to" GridPane.rowIndex="2"/>
<ComboBox fx:id="target" prefWidth="160" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<ComboBox fx:id="tStation" prefWidth="160" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<ComboBox fx:id="target" prefWidth="170" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<ComboBox fx:id="tStation" prefWidth="170" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label text="%router.pane.route.jumps" GridPane.rowIndex="4" />
<NumberField fx:id="jumps" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Separator GridPane.columnSpan="2" GridPane.rowIndex="5" GridPane.margin="$separator_margin"/>
<VBox GridPane.columnSpan="2" GridPane.rowIndex="6" spacing="5">
<HBox alignment="CENTER" spacing="5">
<Button fx:id="addBtn" text="%dialog.button.add" onAction="#addStationToRoute" />
<Button fx:id="editBtn" text="%dialog.button.edit" onAction="#editOrders"/>
<Button fx:id="removeBtn" text="%dialog.button.remove" onAction="#removeSelected"/>
</HBox>
<HBox alignment="CENTER" spacing="5">
<Button text="%router.button.recompute" onAction="#recompute"/>
<Button text="%router.button.rebuild" onAction="#rebuild"/>
<Button text="%dialog.button.clear" onAction="#removeAll" />
</HBox>
<HBox alignment="CENTER" spacing="5">
@@ -69,8 +74,8 @@
<TitledPane text="%router.pane.total" minHeight="100" collapsible="false">
<GridPane vgap="4">
<columnConstraints>
<ColumnConstraints minWidth="70"/>
<ColumnConstraints minWidth="160"/>
<ColumnConstraints minWidth="80"/>
<ColumnConstraints minWidth="170"/>
</columnConstraints>
<Label text="%router.pane.ship.balance"/>
<NumberField fx:id="totalBalance" prefWidth="100" GridPane.columnIndex="1" editable="false"/>