Skip to content

Commit a1efac2

Browse files
committed
First version external matrix support
1 parent dbcf6b2 commit a1efac2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2424
-79
lines changed

com.opendoorlogistics.api/src/com/opendoorlogistics/api/IO.java

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ public interface IO {
2020

2121
File getStandardScriptsDir();
2222

23+
/**
24+
* If we're in ODL Studio this returns the file that the current datastore was loaded from.
25+
* Unlikely to work in ODL Connect...
26+
* @return
27+
*/
28+
File getLoadedExcelFile();
29+
2330
boolean exportDatastore(ODLDatastore<? extends ODLTableReadOnly> ds, File file, boolean xlsx,ProcessingApi processing, ExecutionReport report);
2431

2532
ODLDatastoreAlterable<ODLTableAlterable> importFile(File file, ImportFileType type,ProcessingApi processingApi, ExecutionReport report);

com.opendoorlogistics.api/src/com/opendoorlogistics/api/StandardComponents.java

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.opendoorlogistics.api.standardcomponents.GanntChart;
1010
import com.opendoorlogistics.api.standardcomponents.LineGraph;
1111
import com.opendoorlogistics.api.standardcomponents.Maps;
12+
import com.opendoorlogistics.api.standardcomponents.MatrixExporter;
1213
import com.opendoorlogistics.api.standardcomponents.Reporter;
1314
import com.opendoorlogistics.api.standardcomponents.ScheduleEditor;
1415
import com.opendoorlogistics.api.standardcomponents.TableCreator;
@@ -22,4 +23,5 @@ public interface StandardComponents {
2223
TableCreator tableCreator();
2324
ScheduleEditor scheduleEditor();
2425
LineGraph lineGraph();
26+
MatrixExporter matrixExporter();
2527
}

com.opendoorlogistics.api/src/com/opendoorlogistics/api/distances/DistancesConfiguration.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ public final class DistancesConfiguration implements Serializable {
1313
private DistancesOutputConfiguration outputConfig = new DistancesOutputConfiguration();
1414
private GreatCircleConfiguration greatCircleConfig = new GreatCircleConfiguration();
1515
private GraphhopperConfiguration graphhopperConfig = new GraphhopperConfiguration();
16-
16+
private ExternalMatrixFileConfiguration externalConfig = new ExternalMatrixFileConfiguration();
1717
public enum CalculationMethod {
1818
GREAT_CIRCLE("Crow fly distance (along the surface of the Earth) from one lat/long pair to another"),
19-
ROAD_NETWORK("Use a road network, calculated using the Graphhopper library");
19+
ROAD_NETWORK("Use a road network, calculated using the Graphhopper library"),
20+
EXTERNAL_MATRIX("Use an external text file contain a matrix of distance and time values");
2021

2122
private final String description;
2223

@@ -39,6 +40,10 @@ public DistancesConfiguration deepCopy(){
3940
if(graphhopperConfig!=null){
4041
ret.graphhopperConfig = graphhopperConfig.deepCopy();
4142
}
43+
44+
if(externalConfig!=null){
45+
ret.externalConfig = externalConfig.deepCopy();
46+
}
4247
return ret;
4348
}
4449

@@ -81,6 +86,10 @@ public int hashCode() {
8186
result = prime * result + graphhopperConfig.hashCode();
8287
break;
8388

89+
case EXTERNAL_MATRIX:
90+
result = prime * result + externalConfig.hashCode();
91+
break;
92+
8493
default:
8594
throw new RuntimeException();
8695
}
@@ -119,6 +128,11 @@ public boolean equals(Object obj) {
119128
}
120129
break;
121130

131+
case EXTERNAL_MATRIX:
132+
if(!other.externalConfig.equals(externalConfig)){
133+
return false;
134+
}
135+
break;
122136
default:
123137
throw new RuntimeException();
124138
}
@@ -133,6 +147,14 @@ public GraphhopperConfiguration getGraphhopperConfig() {
133147
public void setGraphhopperConfig(GraphhopperConfiguration graphhopperConfig) {
134148
this.graphhopperConfig = graphhopperConfig;
135149
}
150+
151+
public ExternalMatrixFileConfiguration getExternalConfig() {
152+
return externalConfig;
153+
}
154+
155+
public void setExternalConfig(ExternalMatrixFileConfiguration externalConfig) {
156+
this.externalConfig = externalConfig;
157+
}
136158

137159

138160
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.opendoorlogistics.api.distances;
2+
3+
import java.io.Serializable;
4+
5+
public class ExternalMatrixFileConfiguration implements Serializable {
6+
private boolean useDefaultFile = true;
7+
private String nonDefaultFilename = "";
8+
9+
public boolean isUseDefaultFile() {
10+
return useDefaultFile;
11+
}
12+
13+
public void setUseDefaultFile(boolean useDefaultFile) {
14+
this.useDefaultFile = useDefaultFile;
15+
}
16+
17+
public String getNonDefaultFilename() {
18+
return nonDefaultFilename;
19+
}
20+
21+
public void setNonDefaultFilename(String nonDefaultFilename) {
22+
this.nonDefaultFilename = nonDefaultFilename;
23+
}
24+
25+
public ExternalMatrixFileConfiguration deepCopy(){
26+
ExternalMatrixFileConfiguration ret = new ExternalMatrixFileConfiguration();
27+
ret.setUseDefaultFile(isUseDefaultFile());
28+
ret.setNonDefaultFilename(getNonDefaultFilename());
29+
return ret;
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
final int prime = 31;
35+
int result = 1;
36+
result = prime * result + ((nonDefaultFilename == null) ? 0 : nonDefaultFilename.hashCode());
37+
result = prime * result + (useDefaultFile ? 1231 : 1237);
38+
return result;
39+
}
40+
41+
@Override
42+
public boolean equals(Object obj) {
43+
if (this == obj)
44+
return true;
45+
if (obj == null)
46+
return false;
47+
if (getClass() != obj.getClass())
48+
return false;
49+
ExternalMatrixFileConfiguration other = (ExternalMatrixFileConfiguration) obj;
50+
if (nonDefaultFilename == null) {
51+
if (other.nonDefaultFilename != null)
52+
return false;
53+
} else if (!nonDefaultFilename.equals(other.nonDefaultFilename))
54+
return false;
55+
if (useDefaultFile != other.useDefaultFile)
56+
return false;
57+
return true;
58+
}
59+
60+
}

com.opendoorlogistics.api/src/com/opendoorlogistics/api/distances/ODLCostMatrix.java

+8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ public interface ODLCostMatrix extends ODLTableReadOnly{
1919
long getSizeInBytes();
2020
int getNbFroms();
2121
int getNbTos();
22+
String getFromId(int fromIndex);
23+
String getToId(int toIndex);
2224
// int getNbConnectedSubsets();
2325
// Iterable<String> getConnectedSubset(int i);
2426
boolean getIsConnected(int from, int to);
27+
28+
/**
29+
* For external cost matrices they may become invalid if the file has changed
30+
* @return
31+
*/
32+
boolean isStillValid();
2533
}

com.opendoorlogistics.api/src/com/opendoorlogistics/api/geometry/LatLong.java

+5
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@
1414
public interface LatLong {
1515
double getLatitude();
1616
double getLongitude();
17+
18+
default boolean isValid(){
19+
return getLongitude()>= -180.0 && getLongitude() <= 180.0 && getLatitude() >= -90.0 && getLatitude() <=90.0;
20+
}
21+
1722
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2014 Open Door Logistics (www.opendoorlogistics.com)
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the GNU Lesser Public License v3
5+
* which accompanies this distribution, and is available at http://www.gnu.org/licenses/lgpl.txt
6+
******************************************************************************/
7+
package com.opendoorlogistics.api.standardcomponents;
8+
9+
import java.io.Serializable;
10+
11+
import com.opendoorlogistics.api.components.ODLComponent;
12+
13+
public interface MatrixExporter extends ODLComponent {
14+
Serializable createConfig(boolean exportIds);
15+
}

com.opendoorlogistics.api/src/com/opendoorlogistics/api/tables/ODLTableReadOnly.java

+45-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
******************************************************************************/
77
package com.opendoorlogistics.api.tables;
88

9+
import javax.swing.event.TableModelListener;
10+
import javax.swing.table.TableModel;
911

10-
11-
public interface ODLTableReadOnly extends ODLTableDefinition {
12+
public interface ODLTableReadOnly extends ODLTableDefinition, TableModel {
1213
int getRowCount();
1314
Object getValueAt(int rowIndex, int columnIndex);
1415
Object getValueById(long rowId, int columnIndex);
@@ -35,6 +36,48 @@ public interface ODLTableReadOnly extends ODLTableDefinition {
3536
* @return
3637
*/
3738
long[] find(int col, Object value);
39+
3840

41+
/**
42+
* Needed to make interface compatible with swing TableModel
43+
*/
44+
@Override
45+
default void setValueAt(Object aValue, int rowIndex, int columnIndex){
46+
47+
}
48+
49+
/**
50+
* Needed to make interface compatible with swing TableModel
51+
*/
52+
@Override
53+
default boolean isCellEditable(int rowIndex, int columnIndex){
54+
return false;
55+
}
56+
57+
/**
58+
* Needed to make interface compatible with swing TableModel
59+
*/
60+
@Override
61+
default void addTableModelListener(TableModelListener l){
62+
63+
}
64+
65+
/**
66+
* Needed to make interface compatible with swing TableModel
67+
*/
68+
@Override
69+
default void removeTableModelListener(TableModelListener l){
70+
71+
}
72+
73+
/**
74+
* Needed to make interface compatible with swing TableModel.
75+
* We reutrn string as we only use this for display purposes...
76+
*/
77+
@Override
78+
default Class<?> getColumnClass(int columnIndex){
79+
return String.class;
80+
}
81+
3982
//ODLTableReadOnly findGeo(LatLong min, LatLong max, int zoom, int geomCol);
4083
}

com.opendoorlogistics.components/src/com/opendoorlogistics/components/InitialiseComponents.java

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.opendoorlogistics.components.geocode.postcodes.PCSpatialQueryComponent;
1616
import com.opendoorlogistics.components.heatmap.HeatmapComponent;
1717
import com.opendoorlogistics.components.linegraph.LineGraphComponent;
18+
import com.opendoorlogistics.components.matrixexporter.MatrixExporterComponent;
1819
import com.opendoorlogistics.components.reports.ReporterComponent;
1920
import com.opendoorlogistics.components.reports.builder.ReportsReflectionValidation;
2021
import com.opendoorlogistics.components.scheduleeditor.ScheduleEditorComponent;
@@ -49,6 +50,7 @@ public static void initialise(){
4950
ODLGlobalComponents.register(new ShapefileExporterComponent());
5051
ODLGlobalComponents.register(new LineGraphComponent());
5152
ODLGlobalComponents.register(new HeatmapComponent());
53+
ODLGlobalComponents.register(new MatrixExporterComponent());
5254
registered = true;
5355
}
5456
}

0 commit comments

Comments
 (0)