Skip to content

Commit

Permalink
Sign off on v1.1.0
Browse files Browse the repository at this point in the history
- Updated the project dependencies.
- Added the required tools for the compilation of FlatBuffers schema
files.
- Cleaned up the test classes.
- Added *empty* README files.
- Cleaned up the .idea folder.
- Reformatted and rearranged code.
- Optimized imports.
- Updated copyright.
  • Loading branch information
DimitrisMantas committed Jul 21, 2022
1 parent e1f6d07 commit f66f1d6
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copyright/AGPLv3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added README.md
Empty file.
31 changes: 13 additions & 18 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* Torch is an Android application for the optimal routing of offline
* mobile devices.
* Torch is a model open-source Android application for optimal routing
* in offline mobile devices.
* Copyright (C) 2021-2022 DIMITRIS(.)MANTAS(@outlook.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

Expand All @@ -29,7 +29,7 @@ android {
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0.0"
versionName "1.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -54,22 +54,17 @@ dependencies {
implementation 'com.google.flatbuffers:flatbuffers-java:2.0.3'
implementation 'androidx.core:core-splashscreen:1.0.0-rc01'

implementation 'androidx.activity:activity:1.4.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.activity:activity:1.5.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

implementation 'com.google.android.material:material:1.6.0'
implementation 'com.google.android.material:material:1.6.1'


implementation 'org.mapsforge:vtm:0.17.0'
implementation 'org.mapsforge:vtm-themes:0.17.0'
implementation 'net.sf.kxml:kxml2:2.3.0'
implementation 'org.slf4j:slf4j-api:1.7.28'

implementation 'org.mapsforge:vtm:0.17.0'
implementation 'org.mapsforge:vtm-themes:0.17.0'
implementation 'net.sf.kxml:kxml2:2.3.0'
implementation 'org.slf4j:slf4j-api:1.7.28'
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'org.mapsforge:vtm-android:0.17.0'
implementation 'org.mapsforge:vtm-android:0.17.0:natives-armeabi-v7a'
implementation 'org.mapsforge:vtm-android:0.17.0:natives-arm64-v8a'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* Torch is an Android application for the optimal routing of offline
* mobile devices.
* Torch is a model open-source Android application for optimal routing
* in offline mobile devices.
* Copyright (C) 2021-2022 DIMITRIS(.)MANTAS(@outlook.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dimitrismantas.torch;
Expand All @@ -39,7 +39,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalDouble;
import java.util.Random;

@RunWith(AndroidJUnit4.class)
Expand All @@ -49,16 +48,18 @@ public class InstrumentedTest {
private static final int NUM_TRIALS = 3;
private static final int NUM_WARMUP_TRIALS = NUM_AVERAGED_TRIALS / 10;
private static final int NUM_VERTICES = 8436216;
private static final double TO_MILLI = 1e-6d;
private static final double TO_MILLI = 1E-6D;

private static void warmupDevice() {
ThreadManager.instantiateRoutingServices(InstrumentationRegistry.getInstrumentation().getTargetContext());
// This makes helps make sure that the routing services are actually available before proceeding.
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
final SupplementalMath math = new SupplementalMath();
// This class needs ot be instantiated in order for the RNG to work properly.
final TestMath math = new TestMath();
for (int i = 0; i < NUM_WARMUP_TRIALS; i++) {
final DeserializedVertex source = DataManager.getGraph().vertices(math.random(0, NUM_VERTICES));
final DeserializedVertex target = DataManager.getGraph().vertices(math.random(0, NUM_VERTICES));
Expand All @@ -72,32 +73,21 @@ private static void warmupDevice() {
}
}

private static void writeToFile(final List<Double> list, final String pathname) {
try (final FileWriter writer = new FileWriter(FileManager.getPrimaryStorageDevicePath() + pathname)) {
for (final double measurement : list) {
writer.write(measurement + System.lineSeparator());
}
} catch (IOException e) {
Log.w(LOG_TAG, e);
}
}

private static void measureSingleOptimizationModeApplicationPerformance(final AStar.OptimizationMode optimizationMode, final String tag) {
private static void measureRoutingPerformanceForSingleOptimizationMode(final AStar.OptimizationMode optimizationMode, final String tag) {
warmupDevice();
Log.d(LOG_TAG, "Warmup completed.");
// Instantiate the averaged data lists.
final List<Double> avgR = new ArrayList<>(NUM_AVERAGED_TRIALS);
final List<Double> avgN = new ArrayList<>(NUM_AVERAGED_TRIALS);
final List<Double> avgE = new ArrayList<>(NUM_AVERAGED_TRIALS);
final List<Double> avgL = new ArrayList<>(NUM_AVERAGED_TRIALS);
final List<Double> avgT = new ArrayList<>(NUM_AVERAGED_TRIALS);
final SupplementalMath math = new SupplementalMath();
final TestMath math = new TestMath();
for (int i = 0; i < NUM_AVERAGED_TRIALS; i++) {
final DeserializedVertex source = DataManager.getGraph().vertices(math.random(0, NUM_VERTICES));
final DeserializedVertex target = DataManager.getGraph().vertices(math.random(0, NUM_VERTICES));
// Run each trial multiple times to eliminate possible instabilities.
final List<Integer> R = new ArrayList<>(NUM_TRIALS);
final List<Integer> N = new ArrayList<>(NUM_TRIALS);

final List<Integer> E = new ArrayList<>(NUM_TRIALS);
final List<Integer> L = new ArrayList<>(NUM_TRIALS);
final List<Integer> T = new ArrayList<>(NUM_TRIALS);
Expand All @@ -109,7 +99,7 @@ private static void measureSingleOptimizationModeApplicationPerformance(final AS
final double t0 = System.nanoTime() * TO_MILLI;
final Path route = DataManager.getaStar().run(source, target, optimizationMode);
R.add((int) Math.round((System.nanoTime() * TO_MILLI - t0)));
N.add(route.getN());

E.add(route.getEndpoints().size());
L.add(route.getLength());
T.add(route.getTravelTime());
Expand All @@ -121,31 +111,30 @@ private static void measureSingleOptimizationModeApplicationPerformance(final AS
}
}
avgR.add(math.mean(R));
avgN.add(math.mean(N));

avgE.add(math.mean(E));
avgL.add(math.mean(L));
avgT.add(math.mean(T));
Log.d(LOG_TAG, String.format("Trials Completed: %d", i + 1));
}
writeToFile(avgR, tag + "R.txt");
writeToFile(avgN, tag + "N.txt");
writeToFile(avgE, tag + "E.txt");
writeToFile(avgL, tag + "L.txt");
writeToFile(avgT, tag + "T.txt");
TestFileManager.writeToFile(avgR, tag + "R.txt");
TestFileManager.writeToFile(avgE, tag + "E.txt");
TestFileManager.writeToFile(avgL, tag + "L.txt");
TestFileManager.writeToFile(avgT, tag + "T.txt");
}

@Test
public void measureApplicationPerformance() {
measureSingleOptimizationModeApplicationPerformance(AStar.OptimizationMode.MINIMIZE_DISTANCE, "A-L-");
public void measureRoutingPerformance() {
measureRoutingPerformanceForSingleOptimizationMode(AStar.OptimizationMode.MINIMIZE_DISTANCE, "2-");
Log.d(LOG_TAG, "Torch profiled using the shortest route optimization mode.");
measureSingleOptimizationModeApplicationPerformance(AStar.OptimizationMode.MINIMIZE_TRAVEL_TIME, "A-T-");
measureRoutingPerformanceForSingleOptimizationMode(AStar.OptimizationMode.MINIMIZE_TRAVEL_TIME, "3-");
Log.d(LOG_TAG, "Torch profiled using the fastest route optimization mode.");
}

private static final class SupplementalMath {
private static final class TestMath {
private final Random randomNumberGenerator;

private SupplementalMath() {
private TestMath() {
this.randomNumberGenerator = new Random(362647020392L);
}

Expand All @@ -154,11 +143,18 @@ private int random(final int min, final int max) {
}

private <T> double mean(final List<T> numbers) {
final OptionalDouble mean = numbers.stream().mapToDouble(a -> Double.parseDouble(String.valueOf(a))).average();
if (mean.isPresent()) {
return mean.getAsDouble();
} else {
return Double.NaN;
return numbers.stream().mapToDouble(a -> Double.parseDouble(String.valueOf(a))).average().orElse(Double.NaN);
}
}

private static final class TestFileManager {
private static void writeToFile(final List<Double> list, final String filename) {
try (final FileWriter writer = new FileWriter(FileManager.getPrimaryStorageDevicePath() + filename)) {
for (final double element : list) {
writer.write(element + System.lineSeparator());
}
} catch (IOException e) {
Log.w(LOG_TAG, e);
}
}
}
Expand Down
56 changes: 41 additions & 15 deletions app/src/test/java/com/dimitrismantas/torch/UnitTests.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,61 @@
/*
* Torch is an Android application for the optimal routing of offline
* mobile devices.
* Torch is a model open-source Android application for optimal routing
* in offline mobile devices.
* Copyright (C) 2021-2022 DIMITRIS(.)MANTAS(@outlook.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dimitrismantas.torch;

import static org.junit.Assert.assertEquals;
import com.dimitrismantas.torch.core.main.Path;
import com.dimitrismantas.torch.core.main.engine.AStar;
import com.dimitrismantas.torch.core.main.utils.NearestNeighborSearch;
import com.dimitrismantas.torch.core.utils.serialization.DeserializedGraph;
import com.dimitrismantas.torch.core.utils.serialization.DeserializedVertex;

import org.junit.Test;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class UnitTests {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
public void routingTest() {
final File serializedGraphPath = new File("C:\\Documents\\Torch\\app\\src\\main\\assets\\bin\\grc.bin");

MappedByteBuffer bb = null;
try (final FileChannel fChannel = new RandomAccessFile(serializedGraphPath, "rw").getChannel()) {
bb = fChannel.map(FileChannel.MapMode.PRIVATE, 0, fChannel.size());
} catch (IOException e) {
e.printStackTrace();
}
final DeserializedGraph graph = DeserializedGraph.getRootAsDeserializedGraph(bb);

final double[] origin = {37.9838, 23.7275};
final double[] destination = {40.6401, 22.9444};

final NearestNeighborSearch nns = new NearestNeighborSearch(graph);
final DeserializedVertex s = nns.run(origin[0], origin[1]);
final DeserializedVertex t = nns.run(destination[0], destination[1]);

final AStar aStar = new AStar(graph);
final long t0 = System.nanoTime();
final Path route = aStar.run(s, t, AStar.OptimizationMode.MINIMIZE_DISTANCE);
System.out.println((System.nanoTime() - t0) * 1e-6);
System.out.println(route.getEndpoints().size());
}
}
12 changes: 12 additions & 0 deletions utils/serialization/DeserializedEdge.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This is the eventual destination package of the compiled class.
namespace com.dimitrismantas.torch.core.utils.serialization;

// A table is roughly equivalent to a class in that it has fields of various types with both default and optional values.
table DeserializedEdge {
end_vertex_label:int;
length:short;
travel_time:short;
}

// This is the name of the top-level table in the schema.
root_type DeserializedEdge;
13 changes: 13 additions & 0 deletions utils/serialization/DeserializedGraph.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include "DeserializedVertex.fbs";

// This is the eventual destination package of the compiled class.
namespace com.dimitrismantas.torch.core.utils.serialization;

// A table is roughly equivalent to a class in that it has fields of various types with both default and optional values.

table DeserializedGraph {
vertices:[DeserializedVertex];
}

// This is the name of the top-level table in the schema.
root_type DeserializedGraph;
18 changes: 18 additions & 0 deletions utils/serialization/DeserializedVertex.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include "DeserializedEdge.fbs";

// This is the eventual destination package of the compiled class.
namespace com.dimitrismantas.torch.core.utils.serialization;

// A table is roughly equivalent to a class in that it has fields of various types with both default and optional values.
table DeserializedVertex {
lbl:int;
lat:float;
lon:float;
num_initialized:short = 0;
actual_cost_from_source:int = 0;
predecessor_label:int = -1;
outgoing_edges:[DeserializedEdge];
}

// This is the name of the top-level table in the schema.
root_type DeserializedVertex;
Empty file added utils/serialization/README.md
Empty file.
5 changes: 5 additions & 0 deletions utils/serialization/flatc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flatc --java DeserializedEdge.fbs
flatc --java --gen-mutable DeserializedVertex.fbs
flatc --java DeserializedGraph.fbs
PAUSE
EXIT
Empty file added utils/serialization/flatc.exe
Empty file.

0 comments on commit f66f1d6

Please sign in to comment.