Switch to Maven project.
							
								
								
									
										69
									
								
								.classpath
									
									
									
									
									
								
							
							
						
						@@ -1,69 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<classpath>
 | 
			
		||||
	<classpathentry kind="src" output="target/classes" path="src/main">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="optional" value="true"/>
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="src" output="target/test-classes" path="src/test">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="optional" value="true"/>
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/kxml2-2.3.0.jar"/>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/mapsforge-core-0.9.1.jar">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-core-0.9.1-javadoc.jar!/"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/mapsforge-map-0.9.1.jar">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-map-0.9.1-javadoc.jar!/"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/mapsforge-map-awt-0.9.1.jar">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-map-awt-0.9.1-javadoc.jar!/"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/mapsforge-map-reader-0.9.1.jar">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-map-reader-0.9.1-javadoc.jar!/"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/mapsforge-poi-0.9.1.jar">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-poi-0.9.1-javadoc.jar!/"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/mapsforge-poi-awt-0.9.1.jar">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-poi-awt-0.9.1-javadoc.jar!/"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/mapsforge-themes-0.9.1.jar">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/mapsforge-themes-0.9.1-javadoc.jar!/"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="lib" path="libs/svg-salamander-1.0.jar">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/svg-salamander-1.0-javadoc.jar!/"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
 | 
			
		||||
	<classpathentry kind="lib" path="res"/>
 | 
			
		||||
	<classpathentry kind="output" path="target/classes"/>
 | 
			
		||||
</classpath>
 | 
			
		||||
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						@@ -6,12 +6,14 @@ bin
 | 
			
		||||
target
 | 
			
		||||
doc
 | 
			
		||||
*.jar
 | 
			
		||||
.settings
 | 
			
		||||
.classpath
 | 
			
		||||
 | 
			
		||||
# Editor specific files and folders
 | 
			
		||||
*~
 | 
			
		||||
.project
 | 
			
		||||
 | 
			
		||||
# Project speicific files and folders
 | 
			
		||||
# Project specific files and folders
 | 
			
		||||
*.mapfg
 | 
			
		||||
*.mapgr
 | 
			
		||||
*.path
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
eclipse.preferences.version=1
 | 
			
		||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
 | 
			
		||||
org.eclipse.jdt.core.compiler.compliance=1.8
 | 
			
		||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
 | 
			
		||||
org.eclipse.jdt.core.compiler.source=1.8
 | 
			
		||||
@@ -1,4 +0,0 @@
 | 
			
		||||
activeProfiles=
 | 
			
		||||
eclipse.preferences.version=1
 | 
			
		||||
resolveWorkspaceProjects=true
 | 
			
		||||
version=1
 | 
			
		||||
							
								
								
									
										25
									
								
								be-graphes-algos/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,25 @@
 | 
			
		||||
<?xml version="1.0"?>
 | 
			
		||||
<project
 | 
			
		||||
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
 | 
			
		||||
	xmlns="http://maven.apache.org/POM/4.0.0"
 | 
			
		||||
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 | 
			
		||||
	<modelVersion>4.0.0</modelVersion>
 | 
			
		||||
	<parent>
 | 
			
		||||
		<groupId>org.insa.graphs</groupId>
 | 
			
		||||
		<artifactId>be-graphes-all</artifactId>
 | 
			
		||||
		<version>0.0.1-SNAPSHOT</version>
 | 
			
		||||
	</parent>
 | 
			
		||||
	<artifactId>be-graphes-algos</artifactId>
 | 
			
		||||
	<name>be-graphes-algos</name>
 | 
			
		||||
	<url>http://maven.apache.org</url>
 | 
			
		||||
	<properties>
 | 
			
		||||
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
			
		||||
	</properties>
 | 
			
		||||
	<dependencies>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.insa.graphs</groupId>
 | 
			
		||||
			<artifactId>be-graphes-model</artifactId>
 | 
			
		||||
			<version>${project.version}</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
	</dependencies>
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo;
 | 
			
		||||
package org.insa.graphs.algorithm;
 | 
			
		||||
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
import java.time.Instant;
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package org.insa.algo;
 | 
			
		||||
package org.insa.graphs.algorithm;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.GraphStatistics;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.GraphStatistics;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Base class for algorithm input data classes. This class contains the basic
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo;
 | 
			
		||||
package org.insa.graphs.algorithm;
 | 
			
		||||
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
 | 
			
		||||
@@ -38,6 +38,11 @@ public abstract class AbstractSolution {
 | 
			
		||||
        this.status = Status.UNKNOWN;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * @param data
 | 
			
		||||
     * @param status
 | 
			
		||||
     */
 | 
			
		||||
    protected AbstractSolution(AbstractInputData data, Status status) {
 | 
			
		||||
        this.data = data;
 | 
			
		||||
        this.status = status;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo;
 | 
			
		||||
package org.insa.graphs.algorithm;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Constructor;
 | 
			
		||||
import java.util.IdentityHashMap;
 | 
			
		||||
@@ -7,11 +7,11 @@ import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.TreeSet;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.shortestpath.AStarAlgorithm;
 | 
			
		||||
import org.insa.algo.shortestpath.BellmanFordAlgorithm;
 | 
			
		||||
import org.insa.algo.shortestpath.DijkstraAlgorithm;
 | 
			
		||||
import org.insa.algo.shortestpath.ShortestPathAlgorithm;
 | 
			
		||||
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Factory class used to register and retrieve algorithms based on their common
 | 
			
		||||
@@ -43,8 +43,8 @@ public class AlgorithmFactory {
 | 
			
		||||
     * the given base algorithm.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param baseAlgorithm Base algorithm class that corresponds to the newly
 | 
			
		||||
     *        registered algorithm class (e.g., generic algorithm class for the
 | 
			
		||||
     *        problem).
 | 
			
		||||
     *                      registered algorithm class (e.g., generic algorithm
 | 
			
		||||
     *                      class for the problem).
 | 
			
		||||
     * @param name          Name for the registered algorithm class.
 | 
			
		||||
     * @param algoClass     Algorithm class to register.
 | 
			
		||||
     */
 | 
			
		||||
@@ -67,9 +67,9 @@ public class AlgorithmFactory {
 | 
			
		||||
     * @return A new instance of the given algorithm class using the given data.
 | 
			
		||||
     * 
 | 
			
		||||
     * @throws Exception if something wrong happens when constructing the object,
 | 
			
		||||
     *         i.e. the given input data does not correspond to the given algorithm
 | 
			
		||||
     *         and/or no constructor that takes a single parameter of type
 | 
			
		||||
     *         (data.getClass()) exists.
 | 
			
		||||
     *                   i.e. the given input data does not correspond to the given
 | 
			
		||||
     *                   algorithm and/or no constructor that takes a single
 | 
			
		||||
     *                   parameter of type (data.getClass()) exists.
 | 
			
		||||
     */
 | 
			
		||||
    public static AbstractAlgorithm<?> createAlgorithm(
 | 
			
		||||
            Class<? extends AbstractAlgorithm<?>> algorithm, AbstractInputData data)
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package org.insa.algo;
 | 
			
		||||
package org.insa.graphs.algorithm;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractInputData.Mode;
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.GraphStatistics;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.GraphStatistics;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class can be used to indicate to an algorithm which arcs can be used and
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
package org.insa.algo;
 | 
			
		||||
package org.insa.graphs.algorithm;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.EnumSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractInputData.Mode;
 | 
			
		||||
import org.insa.graph.AccessRestrictions.AccessMode;
 | 
			
		||||
import org.insa.graph.AccessRestrictions.AccessRestriction;
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.GraphStatistics;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.GraphStatistics;
 | 
			
		||||
import org.insa.graphs.model.AccessRestrictions.AccessMode;
 | 
			
		||||
import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
 | 
			
		||||
 | 
			
		||||
public class ArcInspectorFactory {
 | 
			
		||||
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.algo.carpooling;
 | 
			
		||||
package org.insa.graphs.algorithm.carpooling;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractAlgorithm;
 | 
			
		||||
 | 
			
		||||
public abstract class CarPoolingAlgorithm extends AbstractAlgorithm<CarPoolingObserver> {
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package org.insa.graphs.algorithm.carpooling;
 | 
			
		||||
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractInputData;
 | 
			
		||||
import org.insa.graphs.algorithm.ArcInspector;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
 | 
			
		||||
public class CarPoolingData extends AbstractInputData {
 | 
			
		||||
 | 
			
		||||
    protected CarPoolingData(Graph graph, ArcInspector arcFilter) {
 | 
			
		||||
        super(graph, arcFilter);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.carpooling;
 | 
			
		||||
package org.insa.graphs.algorithm.carpooling;
 | 
			
		||||
 | 
			
		||||
public class CarPoolingGraphicObserver implements CarPoolingObserver {
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
package org.insa.graphs.algorithm.carpooling;
 | 
			
		||||
 | 
			
		||||
public interface CarPoolingObserver {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.algo.carpooling;
 | 
			
		||||
package org.insa.graphs.algorithm.carpooling;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractSolution;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractSolution;
 | 
			
		||||
 | 
			
		||||
public class CarPoolingSolution extends AbstractSolution {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.carpooling;
 | 
			
		||||
package org.insa.graphs.algorithm.carpooling;
 | 
			
		||||
 | 
			
		||||
public class CarPoolingTextObserver implements CarPoolingObserver {
 | 
			
		||||
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.algo.packageswitch;
 | 
			
		||||
package org.insa.graphs.algorithm.packageswitch;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractAlgorithm;
 | 
			
		||||
 | 
			
		||||
public abstract class PackageSwitchAlgorithm extends AbstractAlgorithm<PackageSwitchObserver> {
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package org.insa.graphs.algorithm.packageswitch;
 | 
			
		||||
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractInputData;
 | 
			
		||||
import org.insa.graphs.algorithm.ArcInspector;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
 | 
			
		||||
public class PackageSwitchData extends AbstractInputData {
 | 
			
		||||
 | 
			
		||||
    protected PackageSwitchData(Graph graph, ArcInspector arcFilter) {
 | 
			
		||||
        super(graph, arcFilter);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.packageswitch;
 | 
			
		||||
package org.insa.graphs.algorithm.packageswitch;
 | 
			
		||||
 | 
			
		||||
public class PackageSwitchGraphicObserver implements PackageSwitchObserver {
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
package org.insa.graphs.algorithm.packageswitch;
 | 
			
		||||
 | 
			
		||||
public interface PackageSwitchObserver {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.algo.packageswitch;
 | 
			
		||||
package org.insa.graphs.algorithm.packageswitch;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractSolution;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractSolution;
 | 
			
		||||
 | 
			
		||||
public class PackageSwitchSolution extends AbstractSolution {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.packageswitch;
 | 
			
		||||
package org.insa.graphs.algorithm.packageswitch;
 | 
			
		||||
 | 
			
		||||
public class PackageSwitchTextObserver implements PackageSwitchObserver {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.algorithm.shortestpath;
 | 
			
		||||
 | 
			
		||||
public class AStarAlgorithm extends DijkstraAlgorithm {
 | 
			
		||||
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.algorithm.shortestpath;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractSolution.Status;
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
 | 
			
		||||
public class BellmanFordAlgorithm extends ShortestPathAlgorithm {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.algorithm.shortestpath;
 | 
			
		||||
 | 
			
		||||
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
 | 
			
		||||
 | 
			
		||||
@@ -8,7 +8,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected ShortestPathSolution doRun() {
 | 
			
		||||
        ShortestPathData data = getInputData();
 | 
			
		||||
        final ShortestPathData data = getInputData();
 | 
			
		||||
        ShortestPathSolution solution = null;
 | 
			
		||||
        // TODO:
 | 
			
		||||
        return solution;
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.algorithm.shortestpath;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractAlgorithm;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractAlgorithm;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPathObserver> {
 | 
			
		||||
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.algorithm.shortestpath;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractInputData;
 | 
			
		||||
import org.insa.algo.ArcInspector;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractInputData;
 | 
			
		||||
import org.insa.graphs.algorithm.ArcInspector;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public class ShortestPathData extends AbstractInputData {
 | 
			
		||||
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.algorithm.shortestpath;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public interface ShortestPathObserver {
 | 
			
		||||
	
 | 
			
		||||
@@ -1,21 +1,14 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.algorithm.shortestpath;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractInputData.Mode;
 | 
			
		||||
import org.insa.algo.AbstractSolution;
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractSolution;
 | 
			
		||||
 | 
			
		||||
public class ShortestPathSolution extends AbstractSolution {
 | 
			
		||||
 | 
			
		||||
    // Optimal solution.
 | 
			
		||||
    private Path path;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritDoc}
 | 
			
		||||
     */
 | 
			
		||||
    public ShortestPathSolution(ShortestPathData data) {
 | 
			
		||||
        super(data);
 | 
			
		||||
    }
 | 
			
		||||
    private final Path path;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new infeasible shortest-path solution for the given input and
 | 
			
		||||
@@ -26,6 +19,7 @@ public class ShortestPathSolution extends AbstractSolution {
 | 
			
		||||
     */
 | 
			
		||||
    public ShortestPathSolution(ShortestPathData data, Status status) {
 | 
			
		||||
        super(data, status);
 | 
			
		||||
        this.path = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.algorithm.shortestpath;
 | 
			
		||||
 | 
			
		||||
import java.io.PrintStream;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public class ShortestPathTextObserver implements ShortestPathObserver {
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,205 @@
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Implements a binary heap containing elements of type E.
 | 
			
		||||
 *
 | 
			
		||||
 * Note that all comparisons are based on the compareTo method, hence E must
 | 
			
		||||
 * implement Comparable
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Mark Allen Weiss
 | 
			
		||||
 * @author DLB
 | 
			
		||||
 */
 | 
			
		||||
public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
 | 
			
		||||
 | 
			
		||||
    // Number of elements in heap.
 | 
			
		||||
    private int currentSize;
 | 
			
		||||
 | 
			
		||||
    // The heap array.
 | 
			
		||||
    protected final ArrayList<E> array;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a new empty binary heap.
 | 
			
		||||
     */
 | 
			
		||||
    public BinaryHeap() {
 | 
			
		||||
        this.currentSize = 0;
 | 
			
		||||
        this.array = new ArrayList<E>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a copy of the given heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param heap Binary heap to copy.
 | 
			
		||||
     */
 | 
			
		||||
    public BinaryHeap(BinaryHeap<E> heap) {
 | 
			
		||||
        this.currentSize = heap.currentSize;
 | 
			
		||||
        this.array = new ArrayList<E>(heap.array);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set an element at the given index.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param index Index at which the element should be set.
 | 
			
		||||
     * @param value Element to set.
 | 
			
		||||
     */
 | 
			
		||||
    private void arraySet(int index, E value) {
 | 
			
		||||
        if (index == this.array.size()) {
 | 
			
		||||
            this.array.add(value);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            this.array.set(index, value);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Index of the parent of the given index.
 | 
			
		||||
     */
 | 
			
		||||
    protected int indexParent(int index) {
 | 
			
		||||
        return (index - 1) / 2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Index of the left child of the given index.
 | 
			
		||||
     */
 | 
			
		||||
    protected int indexLeft(int index) {
 | 
			
		||||
        return index * 2 + 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Internal method to percolate up in the heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param index Index at which the percolate begins.
 | 
			
		||||
     */
 | 
			
		||||
    private void percolateUp(int index) {
 | 
			
		||||
        E x = this.array.get(index);
 | 
			
		||||
 | 
			
		||||
        for (; index > 0
 | 
			
		||||
                && x.compareTo(this.array.get(indexParent(index))) < 0; index = indexParent(
 | 
			
		||||
                        index)) {
 | 
			
		||||
            E moving_val = this.array.get(indexParent(index));
 | 
			
		||||
            this.arraySet(index, moving_val);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.arraySet(index, x);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Internal method to percolate down in the heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param index Index at which the percolate begins.
 | 
			
		||||
     */
 | 
			
		||||
    private void percolateDown(int index) {
 | 
			
		||||
        int ileft = indexLeft(index);
 | 
			
		||||
        int iright = ileft + 1;
 | 
			
		||||
 | 
			
		||||
        if (ileft < this.currentSize) {
 | 
			
		||||
            E current = this.array.get(index);
 | 
			
		||||
            E left = this.array.get(ileft);
 | 
			
		||||
            boolean hasRight = iright < this.currentSize;
 | 
			
		||||
            E right = (hasRight) ? this.array.get(iright) : null;
 | 
			
		||||
 | 
			
		||||
            if (!hasRight || left.compareTo(right) < 0) {
 | 
			
		||||
                // Left is smaller
 | 
			
		||||
                if (left.compareTo(current) < 0) {
 | 
			
		||||
                    this.arraySet(index, left);
 | 
			
		||||
                    this.arraySet(ileft, current);
 | 
			
		||||
                    this.percolateDown(ileft);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                // Right is smaller
 | 
			
		||||
                if (right.compareTo(current) < 0) {
 | 
			
		||||
                    this.arraySet(index, right);
 | 
			
		||||
                    this.arraySet(iright, current);
 | 
			
		||||
                    this.percolateDown(iright);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isEmpty() {
 | 
			
		||||
        return this.currentSize == 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int size() {
 | 
			
		||||
        return this.currentSize;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void insert(E x) {
 | 
			
		||||
        int index = this.currentSize++;
 | 
			
		||||
        this.arraySet(index, x);
 | 
			
		||||
        this.percolateUp(index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void remove(E x) throws ElementNotFoundException {
 | 
			
		||||
        // TODO:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public E findMin() throws EmptyPriorityQueueException {
 | 
			
		||||
        if (isEmpty())
 | 
			
		||||
            throw new EmptyPriorityQueueException();
 | 
			
		||||
        return this.array.get(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public E deleteMin() throws EmptyPriorityQueueException {
 | 
			
		||||
        E minItem = findMin();
 | 
			
		||||
        E lastItem = this.array.get(--this.currentSize);
 | 
			
		||||
        this.arraySet(0, lastItem);
 | 
			
		||||
        this.percolateDown(0);
 | 
			
		||||
        return minItem;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a multi-lines string representing a sorted view of this binary heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return a string containing a sorted view this binary heap.
 | 
			
		||||
     */
 | 
			
		||||
    public String toStringSorted() {
 | 
			
		||||
        return BinaryHeapFormatter.toStringSorted(this, -1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a multi-lines string representing a sorted view of this binary heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param maxElement Maximum number of elements to display. or {@code -1} to
 | 
			
		||||
     *                   display all the elements.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return a string containing a sorted view this binary heap.
 | 
			
		||||
     */
 | 
			
		||||
    public String toStringSorted(int maxElement) {
 | 
			
		||||
        return BinaryHeapFormatter.toStringSorted(this, maxElement);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a multi-lines string representing a tree view of this binary heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return a string containing a tree view of this binary heap.
 | 
			
		||||
     */
 | 
			
		||||
    public String toStringTree() {
 | 
			
		||||
        return BinaryHeapFormatter.toStringTree(this, Integer.MAX_VALUE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a multi-lines string representing a tree view of this binary heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param maxDepth Maximum depth of the tree to display.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return a string containing a tree view of this binary heap.
 | 
			
		||||
     */
 | 
			
		||||
    public String toStringTree(int maxDepth) {
 | 
			
		||||
        return BinaryHeapFormatter.toStringTree(this, maxDepth);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return BinaryHeapFormatter.toStringTree(this, 8);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,198 @@
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class BinaryHeapFormatter {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This class is used by {@link #toStringTree}, and simply contains three string
 | 
			
		||||
     * accumulating. This is an immutable class.
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    private static class Context {
 | 
			
		||||
 | 
			
		||||
        // Output text:
 | 
			
		||||
        public final String acu;
 | 
			
		||||
 | 
			
		||||
        // Margin to get back exactly under the current position:
 | 
			
		||||
        public final String margin;
 | 
			
		||||
 | 
			
		||||
        // Last margin used for the last child of a node. The markers are different:
 | 
			
		||||
        public final String lastmargin;
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Creaet a new {@code Context}.
 | 
			
		||||
         * 
 | 
			
		||||
         * @param acu        The accumulated string.
 | 
			
		||||
         * @param margin     The current margin.
 | 
			
		||||
         * @param lastMargin The last margin used.
 | 
			
		||||
         */
 | 
			
		||||
        public Context(String acu, String margin, String lastMargin) {
 | 
			
		||||
            this.acu = acu;
 | 
			
		||||
            this.margin = margin;
 | 
			
		||||
            this.lastmargin = lastMargin;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Creates a new context by appending newlines to this context.
 | 
			
		||||
         * 
 | 
			
		||||
         * @param n Number of newlines to append.
 | 
			
		||||
         * 
 | 
			
		||||
         * @return a new context with {@code n} newlines appended.
 | 
			
		||||
         */
 | 
			
		||||
        public Context appendNewlines(int n) {
 | 
			
		||||
            if (n <= 0) {
 | 
			
		||||
                return this;
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                return (new Context(this.acu + "\n" + this.margin, this.margin, this.lastmargin)
 | 
			
		||||
                        .appendNewlines(n - 1));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Creates a new context by appending the given string to this context.
 | 
			
		||||
         * 
 | 
			
		||||
         * @param count Number of spaces to add to the margin, or {@code null} to use
 | 
			
		||||
         *              the length of the string.
 | 
			
		||||
         * @param text  String to append.
 | 
			
		||||
         * 
 | 
			
		||||
         * @return a new context with {@code text} appended.
 | 
			
		||||
         */
 | 
			
		||||
        public Context appendText(Integer count, String text) {
 | 
			
		||||
            int cnt = (count == null) ? text.length() : count;
 | 
			
		||||
            final String spaces = new String(new char[cnt]).replace('\0', ' ');
 | 
			
		||||
            return new Context(this.acu + text, this.margin + spaces, this.lastmargin + spaces);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Creates a new context by appending a branch to this context.
 | 
			
		||||
         * 
 | 
			
		||||
         * @param n     Number of spaces to add to the margin, or {@code null} to use
 | 
			
		||||
         *              the length of the string.
 | 
			
		||||
         * @param label Name of the branch.
 | 
			
		||||
         * 
 | 
			
		||||
         * @return a new context with the branch appended.
 | 
			
		||||
         */
 | 
			
		||||
        public Context appendBranch(Integer count, String label) {
 | 
			
		||||
            final Context ctxt = this.appendText(count, label);
 | 
			
		||||
 | 
			
		||||
            if (count == null) {
 | 
			
		||||
                return new Context(ctxt.acu + "_", ctxt.margin + "|", ctxt.margin + " ");
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                return new Context(ctxt.acu, ctxt.margin + "|", ctxt.margin + " ")
 | 
			
		||||
                        .appendNewlines(1);
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * Input : ready to write the current node at the current context position.
 | 
			
		||||
     * Output : the last character of acu is the last character of the current node.
 | 
			
		||||
     */
 | 
			
		||||
    protected static <E extends Comparable<E>> Context toStringLoop(BinaryHeap<E> heap,
 | 
			
		||||
            Context ctxt, int node, int max_depth) {
 | 
			
		||||
 | 
			
		||||
        if (max_depth < 0) {
 | 
			
		||||
            return ctxt.appendText(null, "...");
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            E nodeval = heap.array.get(node);
 | 
			
		||||
            String nodevals = nodeval.toString();
 | 
			
		||||
 | 
			
		||||
            ArrayList<Integer> childs = new ArrayList<Integer>();
 | 
			
		||||
            // Add childs
 | 
			
		||||
            int index_left = heap.indexLeft(node);
 | 
			
		||||
            int index_right = index_left + 1;
 | 
			
		||||
 | 
			
		||||
            if (index_left < heap.size()) {
 | 
			
		||||
                childs.add(index_left);
 | 
			
		||||
            }
 | 
			
		||||
            if (index_right < heap.size()) {
 | 
			
		||||
                childs.add(index_right);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Context ctxt2 = childs.isEmpty() ? ctxt.appendText(null, nodevals)
 | 
			
		||||
                    : ctxt.appendBranch(1, nodevals);
 | 
			
		||||
 | 
			
		||||
            for (int ch = 0; ch < childs.size(); ch++) {
 | 
			
		||||
                boolean is_last = (ch == childs.size() - 1);
 | 
			
		||||
                int child = childs.get(ch);
 | 
			
		||||
 | 
			
		||||
                if (is_last) {
 | 
			
		||||
                    Context ctxt3 = new Context(ctxt2.acu, ctxt2.lastmargin, ctxt2.lastmargin);
 | 
			
		||||
                    ctxt2 = new Context(toStringLoop(heap, ctxt3.appendText(null, "___"), child,
 | 
			
		||||
                            max_depth - 1).acu, ctxt2.margin, ctxt2.lastmargin);
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    ctxt2 = new Context(toStringLoop(heap, ctxt2.appendText(null, "___"), child,
 | 
			
		||||
                            max_depth - 1).acu, ctxt2.margin, ctxt2.lastmargin).appendNewlines(2);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ctxt2;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a multi-lines string representing a tree view of the given binary
 | 
			
		||||
     * heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param heap     The binary heap to display.
 | 
			
		||||
     * @param maxDepth Maximum depth of the tree to display.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return a string containing a tree view of the given binary heap.
 | 
			
		||||
     */
 | 
			
		||||
    public static <E extends Comparable<E>> String toStringTree(BinaryHeap<E> heap, int maxDepth) {
 | 
			
		||||
        final Context init_context = new Context("   ", "   ", "   ");
 | 
			
		||||
        final Context result = toStringLoop(heap, init_context, 0, maxDepth);
 | 
			
		||||
        return result.acu;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a multi-lines string representing a sorted view of the given binary
 | 
			
		||||
     * heap.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param heap       The binary heap to display.
 | 
			
		||||
     * @param maxElement Maximum number of elements to display. or {@code -1} to
 | 
			
		||||
     *                   display all the elements.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return a string containing a sorted view the given binary heap.
 | 
			
		||||
     */
 | 
			
		||||
    public static <E extends Comparable<E>> String toStringSorted(BinaryHeap<E> heap,
 | 
			
		||||
            int max_elements) {
 | 
			
		||||
        String result = "";
 | 
			
		||||
        final BinaryHeap<E> copy = new BinaryHeap<E>(heap);
 | 
			
		||||
 | 
			
		||||
        final String truncate;
 | 
			
		||||
        if (max_elements < 0 || max_elements >= heap.size()) {
 | 
			
		||||
            truncate = "";
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            truncate = ", only " + max_elements + " elements are shown";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        result += "========  Sorted HEAP  (size = " + heap.size() + truncate + ")  ========\n\n";
 | 
			
		||||
 | 
			
		||||
        while (!copy.isEmpty() && max_elements-- != 0) {
 | 
			
		||||
            result += copy.deleteMin() + "\n";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        result += "\n--------  End of heap  --------";
 | 
			
		||||
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        final BinaryHeap<Integer> heap = new BinaryHeap<Integer>();
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < 12; i++) {
 | 
			
		||||
            heap.insert(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        System.out.println(heap.toStringSorted(-1));
 | 
			
		||||
        System.out.println(heap.toStringTree(6));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.utils;
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
import java.util.SortedSet;
 | 
			
		||||
import java.util.TreeSet;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.utils;
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
public class ElementNotFoundException extends RuntimeException {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.utils;
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
public class EmptyPriorityQueueException extends RuntimeException {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.utils;
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Interface representing a basic priority queue.
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package org.insa.algo.weakconnectivity;
 | 
			
		||||
package org.insa.graphs.algorithm.weakconnectivity;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public interface WeaklyConnectedComponentObserver {
 | 
			
		||||
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
package org.insa.algo.weakconnectivity;
 | 
			
		||||
package org.insa.graphs.algorithm.weakconnectivity;
 | 
			
		||||
 | 
			
		||||
import java.io.PrintStream;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public class WeaklyConnectedComponentTextObserver implements WeaklyConnectedComponentObserver {
 | 
			
		||||
	
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.weakconnectivity;
 | 
			
		||||
package org.insa.graphs.algorithm.weakconnectivity;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
@@ -6,11 +6,11 @@ import java.util.HashSet;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.Queue;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractAlgorithm;
 | 
			
		||||
import org.insa.algo.AbstractSolution.Status;
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public class WeaklyConnectedComponentsAlgorithm
 | 
			
		||||
        extends AbstractAlgorithm<WeaklyConnectedComponentObserver> {
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
package org.insa.algo.weakconnectivity;
 | 
			
		||||
package org.insa.graphs.algorithm.weakconnectivity;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractInputData;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractInputData;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
 | 
			
		||||
public class WeaklyConnectedComponentsData extends AbstractInputData {
 | 
			
		||||
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
package org.insa.algo.weakconnectivity;
 | 
			
		||||
package org.insa.graphs.algorithm.weakconnectivity;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractSolution;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractSolution;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public class WeaklyConnectedComponentsSolution extends AbstractSolution {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.utils;
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
public class BinaryHeapTest extends PriorityQueueTest {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.utils;
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
public class BinarySearchTreeTest extends PriorityQueueTest {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.algo.utils;
 | 
			
		||||
package org.insa.graphs.algorithm.utils;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
							
								
								
									
										84
									
								
								be-graphes-gui/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,84 @@
 | 
			
		||||
<?xml version="1.0"?>
 | 
			
		||||
<project
 | 
			
		||||
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
 | 
			
		||||
	xmlns="http://maven.apache.org/POM/4.0.0"
 | 
			
		||||
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 | 
			
		||||
	<modelVersion>4.0.0</modelVersion>
 | 
			
		||||
	<parent>
 | 
			
		||||
		<groupId>org.insa.graphs</groupId>
 | 
			
		||||
		<artifactId>be-graphes-all</artifactId>
 | 
			
		||||
		<version>0.0.1-SNAPSHOT</version>
 | 
			
		||||
	</parent>
 | 
			
		||||
	
 | 
			
		||||
	<properties>
 | 
			
		||||
	   <mapsforge.version>0.13.0</mapsforge.version>
 | 
			
		||||
	</properties>
 | 
			
		||||
	
 | 
			
		||||
	<artifactId>be-graphes-gui</artifactId>
 | 
			
		||||
	<name>be-graphes-gui</name>
 | 
			
		||||
	
 | 
			
		||||
	<repositories>
 | 
			
		||||
        <repository>
 | 
			
		||||
            <id>jitpack.io</id>
 | 
			
		||||
            <url>https://jitpack.io</url>
 | 
			
		||||
        </repository>
 | 
			
		||||
    </repositories>
 | 
			
		||||
 | 
			
		||||
	<dependencies>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.insa.graphs</groupId>
 | 
			
		||||
			<artifactId>be-graphes-model</artifactId>
 | 
			
		||||
			<version>${project.version}</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.insa.graphs</groupId>
 | 
			
		||||
			<artifactId>be-graphes-algos</artifactId>
 | 
			
		||||
			<version>${project.version}</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
 | 
			
		||||
		<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-core -->
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>net.sf.kxml</groupId>
 | 
			
		||||
			<artifactId>kxml2</artifactId>
 | 
			
		||||
			<version>2.3.0</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
 | 
			
		||||
        <!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader -->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.mapsforge</groupId>
 | 
			
		||||
            <artifactId>mapsforge-themes</artifactId>
 | 
			
		||||
            <version>${mapsforge.version}</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
		<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map -->
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.mapsforge</groupId>
 | 
			
		||||
			<artifactId>mapsforge-map</artifactId>
 | 
			
		||||
            <version>${mapsforge.version}</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
 | 
			
		||||
		<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-awt -->
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.mapsforge</groupId>
 | 
			
		||||
			<artifactId>mapsforge-map-awt</artifactId>
 | 
			
		||||
            <version>${mapsforge.version}</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
 | 
			
		||||
        <!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader -->
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.mapsforge</groupId>
 | 
			
		||||
            <artifactId>mapsforge-themes</artifactId>
 | 
			
		||||
            <version>${mapsforge.version}</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
		<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader -->
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.mapsforge</groupId>
 | 
			
		||||
			<artifactId>mapsforge-map-reader</artifactId>
 | 
			
		||||
            <version>${mapsforge.version}</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
 | 
			
		||||
	</dependencies>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Component;
 | 
			
		||||
@@ -22,15 +22,14 @@ import javax.swing.JLabel;
 | 
			
		||||
import javax.swing.JPanel;
 | 
			
		||||
import javax.swing.border.EmptyBorder;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractAlgorithm;
 | 
			
		||||
import org.insa.algo.AlgorithmFactory;
 | 
			
		||||
import org.insa.algo.ArcInspector;
 | 
			
		||||
import org.insa.algo.ArcInspectorFactory;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphics.NodesInputPanel.InputChangedEvent;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.components.MapViewDrawing;
 | 
			
		||||
import org.insa.graphics.utils.ColorUtils;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.AlgorithmFactory;
 | 
			
		||||
import org.insa.graphs.algorithm.ArcInspector;
 | 
			
		||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
 | 
			
		||||
import org.insa.graphs.gui.NodesInputPanel.InputChangedEvent;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.utils.ColorUtils;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
 | 
			
		||||
 | 
			
		||||
@@ -118,9 +117,6 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
 | 
			
		||||
    // Graphic / Text checkbox observer
 | 
			
		||||
    private final JCheckBox graphicObserverCheckbox, textualObserverCheckbox;
 | 
			
		||||
 | 
			
		||||
    // Drawing
 | 
			
		||||
    private Drawing drawing = null;
 | 
			
		||||
 | 
			
		||||
    private JButton startAlgoButton;
 | 
			
		||||
 | 
			
		||||
    // Start listeners
 | 
			
		||||
@@ -360,7 +356,7 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
 | 
			
		||||
        for (JComponent component: components) {
 | 
			
		||||
            component.setEnabled(enabled);
 | 
			
		||||
        }
 | 
			
		||||
        graphicObserverCheckbox.setEnabled(enabled && !(drawing instanceof MapViewDrawing));
 | 
			
		||||
        graphicObserverCheckbox.setEnabled(enabled);
 | 
			
		||||
        enabled = enabled && allNotNull(this.nodesInputPanel.getNodeForInputs());
 | 
			
		||||
        startAlgoButton.setEnabled(enabled);
 | 
			
		||||
    }
 | 
			
		||||
@@ -376,15 +372,6 @@ public class AlgorithmPanel extends JPanel implements DrawingChangeListener {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onDrawingLoaded(Drawing oldDrawing, Drawing newDrawing) {
 | 
			
		||||
        if (newDrawing instanceof MapViewDrawing) {
 | 
			
		||||
            graphicObserverCheckbox.setSelected(false);
 | 
			
		||||
            graphicObserverCheckbox.setEnabled(false);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            graphicObserverCheckbox.setSelected(true);
 | 
			
		||||
            graphicObserverCheckbox.setEnabled(true);
 | 
			
		||||
        }
 | 
			
		||||
        this.drawing = newDrawing;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.awt.Component;
 | 
			
		||||
import java.awt.event.ActionEvent;
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
 | 
			
		||||
public interface DrawingChangeListener {
 | 
			
		||||
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
 | 
			
		||||
public interface GraphChangeListener {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.awt.Component;
 | 
			
		||||
 | 
			
		||||
@@ -11,10 +11,10 @@ import javax.swing.JPanel;
 | 
			
		||||
import javax.swing.JProgressBar;
 | 
			
		||||
import javax.swing.border.EmptyBorder;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graph.RoadInformation;
 | 
			
		||||
import org.insa.graph.io.GraphReaderObserver;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
import org.insa.graphs.model.RoadInformation;
 | 
			
		||||
import org.insa.graphs.model.io.GraphReaderObserver;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * One-time use GraphReaderObserver that display progress in three different
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.awt.BorderLayout;
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
@@ -43,34 +43,34 @@ import javax.swing.UIManager;
 | 
			
		||||
import javax.swing.border.CompoundBorder;
 | 
			
		||||
import javax.swing.border.EmptyBorder;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractSolution;
 | 
			
		||||
import org.insa.algo.AlgorithmFactory;
 | 
			
		||||
import org.insa.algo.carpooling.CarPoolingAlgorithm;
 | 
			
		||||
import org.insa.algo.packageswitch.PackageSwitchAlgorithm;
 | 
			
		||||
import org.insa.algo.shortestpath.ShortestPathAlgorithm;
 | 
			
		||||
import org.insa.algo.shortestpath.ShortestPathData;
 | 
			
		||||
import org.insa.algo.shortestpath.ShortestPathGraphicObserver;
 | 
			
		||||
import org.insa.algo.shortestpath.ShortestPathSolution;
 | 
			
		||||
import org.insa.algo.shortestpath.ShortestPathTextObserver;
 | 
			
		||||
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentGraphicObserver;
 | 
			
		||||
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentTextObserver;
 | 
			
		||||
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
 | 
			
		||||
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentsData;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graph.io.BinaryGraphReader;
 | 
			
		||||
import org.insa.graph.io.BinaryPathReader;
 | 
			
		||||
import org.insa.graph.io.GraphReader;
 | 
			
		||||
import org.insa.graph.io.MapMismatchException;
 | 
			
		||||
import org.insa.graphics.AlgorithmPanel.StartActionEvent;
 | 
			
		||||
import org.insa.graphics.drawing.BasicGraphPalette;
 | 
			
		||||
import org.insa.graphics.drawing.BlackAndWhiteGraphPalette;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.GraphPalette;
 | 
			
		||||
import org.insa.graphics.drawing.components.BasicDrawing;
 | 
			
		||||
import org.insa.graphics.drawing.components.MapViewDrawing;
 | 
			
		||||
import org.insa.graphics.utils.FileUtils;
 | 
			
		||||
import org.insa.graphics.utils.FileUtils.FolderType;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractSolution;
 | 
			
		||||
import org.insa.graphs.algorithm.AlgorithmFactory;
 | 
			
		||||
import org.insa.graphs.algorithm.carpooling.CarPoolingAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.packageswitch.PackageSwitchAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathTextObserver;
 | 
			
		||||
import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentTextObserver;
 | 
			
		||||
import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
 | 
			
		||||
import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentsData;
 | 
			
		||||
import org.insa.graphs.gui.AlgorithmPanel.StartActionEvent;
 | 
			
		||||
import org.insa.graphs.gui.drawing.BasicGraphPalette;
 | 
			
		||||
import org.insa.graphs.gui.drawing.BlackAndWhiteGraphPalette;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.GraphPalette;
 | 
			
		||||
import org.insa.graphs.gui.drawing.components.BasicDrawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.components.MapViewDrawing;
 | 
			
		||||
import org.insa.graphs.gui.observers.ShortestPathGraphicObserver;
 | 
			
		||||
import org.insa.graphs.gui.observers.WeaklyConnectedComponentGraphicObserver;
 | 
			
		||||
import org.insa.graphs.gui.utils.FileUtils;
 | 
			
		||||
import org.insa.graphs.gui.utils.FileUtils.FolderType;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
import org.insa.graphs.model.io.BinaryGraphReader;
 | 
			
		||||
import org.insa.graphs.model.io.BinaryPathReader;
 | 
			
		||||
import org.insa.graphs.model.io.GraphReader;
 | 
			
		||||
import org.insa.graphs.model.io.MapMismatchException;
 | 
			
		||||
 | 
			
		||||
public class MainWindow extends JFrame {
 | 
			
		||||
 | 
			
		||||
@@ -157,7 +157,7 @@ public class MainWindow extends JFrame {
 | 
			
		||||
        this.currentPalette = this.basicPalette;
 | 
			
		||||
 | 
			
		||||
        wccPanel = new AlgorithmPanel(this, WeaklyConnectedComponentsAlgorithm.class,
 | 
			
		||||
                "Weakly-Connected Components", new String[]{}, false);
 | 
			
		||||
                "Weakly-Connected Components", new String[] {}, false);
 | 
			
		||||
        wccPanel.addStartActionListener(new ActionListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void actionPerformed(ActionEvent e) {
 | 
			
		||||
@@ -202,7 +202,7 @@ public class MainWindow extends JFrame {
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        spPanel = new AlgorithmPanel(this, ShortestPathAlgorithm.class, "Shortest-Path",
 | 
			
		||||
                new String[]{ "Origin", "Destination" }, true);
 | 
			
		||||
                new String[] { "Origin", "Destination" }, true);
 | 
			
		||||
        spPanel.addStartActionListener(new ActionListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void actionPerformed(ActionEvent e) {
 | 
			
		||||
@@ -254,12 +254,12 @@ public class MainWindow extends JFrame {
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        cpPanel = new AlgorithmPanel(this, CarPoolingAlgorithm.class, "Car-Pooling", new String[]{
 | 
			
		||||
        cpPanel = new AlgorithmPanel(this, CarPoolingAlgorithm.class, "Car-Pooling", new String[] {
 | 
			
		||||
                "Origin Car", "Origin Pedestrian", "Destination Car", "Destination Pedestrian" },
 | 
			
		||||
                true);
 | 
			
		||||
 | 
			
		||||
        psPanel = new AlgorithmPanel(this, PackageSwitchAlgorithm.class, "Car-Pooling",
 | 
			
		||||
                new String[]{ "Oribin A", "Origin B", "Destination A", "Destination B" }, true);
 | 
			
		||||
                new String[] { "Oribin A", "Origin B", "Destination A", "Destination B" }, true);
 | 
			
		||||
 | 
			
		||||
        // add algorithm panels
 | 
			
		||||
        algoPanels.add(wccPanel);
 | 
			
		||||
@@ -296,7 +296,9 @@ public class MainWindow extends JFrame {
 | 
			
		||||
                JFileChooser chooser = FileUtils.createFileChooser(FolderType.Map);
 | 
			
		||||
                if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
 | 
			
		||||
                    graphFilePath = chooser.getSelectedFile().getAbsolutePath();
 | 
			
		||||
                    DataInputStream stream;
 | 
			
		||||
 | 
			
		||||
                    // Note: Don't use a try-resources block since loadGraph is asynchronous.
 | 
			
		||||
                    final DataInputStream stream;
 | 
			
		||||
                    try {
 | 
			
		||||
                        stream = new DataInputStream(new BufferedInputStream(
 | 
			
		||||
                                new FileInputStream(chooser.getSelectedFile())));
 | 
			
		||||
@@ -579,13 +581,15 @@ public class MainWindow extends JFrame {
 | 
			
		||||
                reader.addObserver(progressBar);
 | 
			
		||||
                try {
 | 
			
		||||
                    graph = reader.read();
 | 
			
		||||
                    reader.close();
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception exception) {
 | 
			
		||||
                    progressBar.setVisible(false);
 | 
			
		||||
                    progressBar.dispose();
 | 
			
		||||
                    progressBar = null;
 | 
			
		||||
                    JOptionPane.showMessageDialog(MainWindow.this,
 | 
			
		||||
                            "Unable to read graph from the selected file.");
 | 
			
		||||
                            "<html><p>Unable to read graph from the selected file:</p><p>"
 | 
			
		||||
                                    + exception.getMessage() + "</p>");
 | 
			
		||||
                    exception.printStackTrace(System.out);
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
@@ -645,29 +649,22 @@ public class MainWindow extends JFrame {
 | 
			
		||||
            public void actionPerformed(ActionEvent e) {
 | 
			
		||||
                JFileChooser chooser = FileUtils.createFileChooser(FolderType.PathInput);
 | 
			
		||||
                if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
 | 
			
		||||
                    BinaryPathReader reader;
 | 
			
		||||
                    try {
 | 
			
		||||
                        reader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(
 | 
			
		||||
                                new FileInputStream(chooser.getSelectedFile()))));
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (IOException e1) {
 | 
			
		||||
                        JOptionPane.showMessageDialog(MainWindow.this,
 | 
			
		||||
                                "Cannot open the selected file.");
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
                    try {
 | 
			
		||||
                    try (BinaryPathReader reader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(
 | 
			
		||||
                            new FileInputStream(chooser.getSelectedFile()))))){
 | 
			
		||||
                        Path path = reader.readPath(graph);
 | 
			
		||||
                        pathPanel.addPath(path);
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (MapMismatchException exception) {
 | 
			
		||||
                        JOptionPane.showMessageDialog(MainWindow.this,
 | 
			
		||||
                                "The selected file does not contain a path for the current graph.");
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (IOException e1) {
 | 
			
		||||
                        JOptionPane.showMessageDialog(MainWindow.this,
 | 
			
		||||
                                "Cannot open the selected file.");
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception exception) {
 | 
			
		||||
                        JOptionPane.showMessageDialog(MainWindow.this,
 | 
			
		||||
                                "Unable to read path from the selected file.");
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Font;
 | 
			
		||||
@@ -21,13 +21,13 @@ import javax.swing.JTextField;
 | 
			
		||||
import javax.swing.event.DocumentEvent;
 | 
			
		||||
import javax.swing.event.DocumentListener;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graph.Point;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing.AlphaMode;
 | 
			
		||||
import org.insa.graphics.drawing.DrawingClickListener;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.MarkerOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing.AlphaMode;
 | 
			
		||||
import org.insa.graphs.gui.drawing.DrawingClickListener;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.MarkerOverlay;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
import org.insa.graphs.model.Point;
 | 
			
		||||
 | 
			
		||||
public class NodesInputPanel extends JPanel
 | 
			
		||||
        implements DrawingClickListener, DrawingChangeListener, GraphChangeListener {
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Component;
 | 
			
		||||
@@ -32,14 +32,14 @@ import javax.swing.border.EmptyBorder;
 | 
			
		||||
import javax.swing.event.ChangeEvent;
 | 
			
		||||
import javax.swing.event.ChangeListener;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graph.io.BinaryPathWriter;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphics.utils.ColorUtils;
 | 
			
		||||
import org.insa.graphics.utils.FileUtils;
 | 
			
		||||
import org.insa.graphics.utils.FileUtils.FolderType;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphs.gui.utils.ColorUtils;
 | 
			
		||||
import org.insa.graphs.gui.utils.FileUtils;
 | 
			
		||||
import org.insa.graphs.gui.utils.FileUtils.FolderType;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
import org.insa.graphs.model.io.BinaryPathWriter;
 | 
			
		||||
 | 
			
		||||
public class PathsPanel extends JPanel implements DrawingChangeListener, GraphChangeListener {
 | 
			
		||||
 | 
			
		||||
@@ -232,9 +232,8 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
 | 
			
		||||
                    if (chooser
 | 
			
		||||
                            .showSaveDialog(getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
 | 
			
		||||
                        File file = chooser.getSelectedFile();
 | 
			
		||||
                        try {
 | 
			
		||||
                            BinaryPathWriter writer = new BinaryPathWriter(new DataOutputStream(
 | 
			
		||||
                                    new BufferedOutputStream(new FileOutputStream(file))));
 | 
			
		||||
                        try (BinaryPathWriter writer = new BinaryPathWriter(new DataOutputStream(
 | 
			
		||||
                                    new BufferedOutputStream(new FileOutputStream(file))))) {
 | 
			
		||||
                            writer.writePath(path);
 | 
			
		||||
                        }
 | 
			
		||||
                        catch (IOException e1) {
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
import java.time.Instant;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Component;
 | 
			
		||||
@@ -19,12 +19,12 @@ import javax.swing.JPanel;
 | 
			
		||||
import javax.swing.border.CompoundBorder;
 | 
			
		||||
import javax.swing.border.EmptyBorder;
 | 
			
		||||
 | 
			
		||||
import org.insa.algo.AbstractInputData;
 | 
			
		||||
import org.insa.algo.AbstractSolution;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractInputData;
 | 
			
		||||
import org.insa.graphs.algorithm.AbstractSolution;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
 | 
			
		||||
public class SolutionPanel extends JPanel implements DrawingChangeListener, GraphChangeListener {
 | 
			
		||||
 | 
			
		||||
@@ -122,6 +122,7 @@ public class SolutionPanel extends JPanel implements DrawingChangeListener, Grap
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * (non-Javadoc)
 | 
			
		||||
         * 
 | 
			
		||||
         * @see java.lang.Object#toString()
 | 
			
		||||
         */
 | 
			
		||||
        public String toString() {
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics;
 | 
			
		||||
package org.insa.graphs.gui;
 | 
			
		||||
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
import java.time.Instant;
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
package org.insa.graphics.drawing;
 | 
			
		||||
package org.insa.graphs.gui.drawing;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.RoadInformation.RoadType;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.RoadInformation.RoadType;
 | 
			
		||||
 | 
			
		||||
public class BasicGraphPalette implements GraphPalette {
 | 
			
		||||
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package org.insa.graphics.drawing;
 | 
			
		||||
package org.insa.graphs.gui.drawing;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
 | 
			
		||||
public class BlackAndWhiteGraphPalette extends BasicGraphPalette {
 | 
			
		||||
 | 
			
		||||
@@ -1,13 +1,13 @@
 | 
			
		||||
package org.insa.graphics.drawing;
 | 
			
		||||
package org.insa.graphs.gui.drawing;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graph.Point;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.MarkerOverlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.MarkerOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
import org.insa.graphs.model.Point;
 | 
			
		||||
 | 
			
		||||
public interface Drawing {
 | 
			
		||||
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.graphics.drawing;
 | 
			
		||||
package org.insa.graphs.gui.drawing;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Point;
 | 
			
		||||
import org.insa.graphs.model.Point;
 | 
			
		||||
 | 
			
		||||
public interface DrawingClickListener {
 | 
			
		||||
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package org.insa.graphics.drawing;
 | 
			
		||||
package org.insa.graphs.gui.drawing;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
 | 
			
		||||
public interface GraphPalette {
 | 
			
		||||
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package org.insa.graphics.drawing;
 | 
			
		||||
package org.insa.graphs.gui.drawing;
 | 
			
		||||
 | 
			
		||||
import java.awt.Dimension;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.GraphStatistics.BoundingBox;
 | 
			
		||||
import org.insa.graphs.model.GraphStatistics.BoundingBox;
 | 
			
		||||
 | 
			
		||||
public class MercatorProjection implements Projection {
 | 
			
		||||
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.graphics.drawing;
 | 
			
		||||
package org.insa.graphs.gui.drawing;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.GraphStatistics.BoundingBox;
 | 
			
		||||
import org.insa.graphs.model.GraphStatistics.BoundingBox;
 | 
			
		||||
 | 
			
		||||
public class PlateCarreProjection implements Projection {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing;
 | 
			
		||||
package org.insa.graphs.gui.drawing;
 | 
			
		||||
 | 
			
		||||
public interface Projection {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing.components;
 | 
			
		||||
package org.insa.graphs.gui.drawing.components;
 | 
			
		||||
 | 
			
		||||
import java.awt.BasicStroke;
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
@@ -20,24 +20,24 @@ import java.util.List;
 | 
			
		||||
 | 
			
		||||
import javax.swing.JPanel;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.GraphStatistics.BoundingBox;
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graph.Point;
 | 
			
		||||
import org.insa.graphics.drawing.BasicGraphPalette;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.DrawingClickListener;
 | 
			
		||||
import org.insa.graphics.drawing.GraphPalette;
 | 
			
		||||
import org.insa.graphics.drawing.MercatorProjection;
 | 
			
		||||
import org.insa.graphics.drawing.PlateCarreProjection;
 | 
			
		||||
import org.insa.graphics.drawing.Projection;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.MarkerOverlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.MarkerUtils;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.Overlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.BasicGraphPalette;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.DrawingClickListener;
 | 
			
		||||
import org.insa.graphs.gui.drawing.GraphPalette;
 | 
			
		||||
import org.insa.graphs.gui.drawing.MercatorProjection;
 | 
			
		||||
import org.insa.graphs.gui.drawing.PlateCarreProjection;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Projection;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.MarkerOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.MarkerUtils;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.Overlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
import org.insa.graphs.model.Point;
 | 
			
		||||
import org.insa.graphs.model.GraphStatistics.BoundingBox;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing.components;
 | 
			
		||||
package org.insa.graphs.gui.drawing.components;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Graphics;
 | 
			
		||||
@@ -9,22 +9,24 @@ import java.awt.event.ActionListener;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Arc;
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graph.Point;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.DrawingClickListener;
 | 
			
		||||
import org.insa.graphics.drawing.GraphPalette;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.MarkerAutoScaling;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.MarkerOverlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.MarkerUtils;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.Overlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PolylineAutoScaling;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.DrawingClickListener;
 | 
			
		||||
import org.insa.graphs.gui.drawing.GraphPalette;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.MarkerAutoScaling;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.MarkerOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.MarkerUtils;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.Overlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PathOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PolylineAutoScaling;
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
import org.insa.graphs.model.Point;
 | 
			
		||||
import org.mapsforge.core.graphics.GraphicFactory;
 | 
			
		||||
import org.mapsforge.core.model.BoundingBox;
 | 
			
		||||
import org.mapsforge.core.model.LatLong;
 | 
			
		||||
@@ -40,9 +42,10 @@ import org.mapsforge.map.layer.Layers;
 | 
			
		||||
import org.mapsforge.map.layer.cache.TileCache;
 | 
			
		||||
import org.mapsforge.map.layer.hills.HillsRenderConfig;
 | 
			
		||||
import org.mapsforge.map.layer.overlay.Marker;
 | 
			
		||||
import org.mapsforge.map.layer.overlay.Polygon;
 | 
			
		||||
import org.mapsforge.map.layer.renderer.TileRendererLayer;
 | 
			
		||||
import org.mapsforge.map.model.DisplayModel;
 | 
			
		||||
import org.mapsforge.map.model.MapViewPosition;
 | 
			
		||||
import org.mapsforge.map.model.IMapViewPosition;
 | 
			
		||||
import org.mapsforge.map.model.Model;
 | 
			
		||||
import org.mapsforge.map.reader.MapFile;
 | 
			
		||||
import org.mapsforge.map.rendertheme.InternalRenderTheme;
 | 
			
		||||
@@ -191,8 +194,56 @@ public class MapViewDrawing extends MapView implements Drawing {
 | 
			
		||||
     */
 | 
			
		||||
    private class MapViewPointSetOverlay extends MapViewOverlay implements PointSetOverlay {
 | 
			
		||||
 | 
			
		||||
        private List<Point> points = new ArrayList<>();
 | 
			
		||||
        private final Polygon polygon;
 | 
			
		||||
 | 
			
		||||
        private List<Point> convexHull(List<Point> p) {
 | 
			
		||||
            if (p.isEmpty()) {
 | 
			
		||||
                return new ArrayList<>();
 | 
			
		||||
            }
 | 
			
		||||
            p.sort((p1, p2) -> Float.compare(p1.getLongitude(), p2.getLongitude()));
 | 
			
		||||
            List<Point> h = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
            // lower hull
 | 
			
		||||
            for (Point pt: p) {
 | 
			
		||||
                while (h.size() >= 2 && !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
 | 
			
		||||
                    h.remove(h.size() - 1);
 | 
			
		||||
                }
 | 
			
		||||
                h.add(pt);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // upper hull
 | 
			
		||||
            int t = h.size() + 1;
 | 
			
		||||
            for (int i = p.size() - 1; i >= 0; i--) {
 | 
			
		||||
                Point pt = p.get(i);
 | 
			
		||||
                while (h.size() >= t && !ccw(h.get(h.size() - 2), h.get(h.size() - 1), pt)) {
 | 
			
		||||
                    h.remove(h.size() - 1);
 | 
			
		||||
                }
 | 
			
		||||
                h.add(pt);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            h.remove(h.size() - 1);
 | 
			
		||||
            return h;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // ccw returns true if the three points make a counter-clockwise turn
 | 
			
		||||
        private boolean ccw(Point a, Point b, Point c) {
 | 
			
		||||
            return ((b.getLongitude() - a.getLongitude())
 | 
			
		||||
                    * (c.getLatitude() - a.getLatitude())) > ((b.getLatitude() - a.getLatitude())
 | 
			
		||||
                            * (c.getLongitude() - a.getLongitude()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public MapViewPointSetOverlay() {
 | 
			
		||||
            super(new Layer[0], Color.BLACK);
 | 
			
		||||
            super(new Layer[] { new Polygon(GRAPHIC_FACTORY.createPaint(), null, GRAPHIC_FACTORY) },
 | 
			
		||||
                    Color.BLACK);
 | 
			
		||||
            polygon = (Polygon) this.layers[0];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public void setColor(Color color) {
 | 
			
		||||
            super.setColor(color);
 | 
			
		||||
            polygon.getPaintFill().setColor(GRAPHIC_FACTORY.createColor(100, color.getRed(),
 | 
			
		||||
                    color.getGreen(), color.getBlue()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
@@ -207,6 +258,11 @@ public class MapViewDrawing extends MapView implements Drawing {
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public void addPoint(Point point) {
 | 
			
		||||
            points.add(point);
 | 
			
		||||
            this.points = convexHull(points);
 | 
			
		||||
            polygon.setPoints(this.points.stream().map(MapViewDrawing.this::convertPoint)
 | 
			
		||||
                    .collect(Collectors.toList()));
 | 
			
		||||
            polygon.requestRedraw();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
@@ -331,7 +387,7 @@ public class MapViewDrawing extends MapView implements Drawing {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private TileRendererLayer createTileRendererLayer(TileCache tileCache,
 | 
			
		||||
            MapDataStore mapDataStore, MapViewPosition mapViewPosition,
 | 
			
		||||
            MapDataStore mapDataStore, IMapViewPosition mapViewPosition,
 | 
			
		||||
            HillsRenderConfig hillsRenderConfig) {
 | 
			
		||||
        TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
 | 
			
		||||
                mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing.components;
 | 
			
		||||
package org.insa.graphs.gui.drawing.components;
 | 
			
		||||
 | 
			
		||||
import java.awt.BasicStroke;
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing.components;
 | 
			
		||||
package org.insa.graphs.gui.drawing.components;
 | 
			
		||||
 | 
			
		||||
import java.awt.Component;
 | 
			
		||||
import java.awt.Point;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing.overlays;
 | 
			
		||||
package org.insa.graphs.gui.drawing.overlays;
 | 
			
		||||
 | 
			
		||||
import java.awt.Graphics2D;
 | 
			
		||||
import java.awt.Image;
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
package org.insa.graphics.drawing.overlays;
 | 
			
		||||
package org.insa.graphs.gui.drawing.overlays;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Point;
 | 
			
		||||
import org.insa.graphs.model.Point;
 | 
			
		||||
 | 
			
		||||
public interface MarkerOverlay extends Overlay {
 | 
			
		||||
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
package org.insa.graphics.drawing.overlays;
 | 
			
		||||
package org.insa.graphs.gui.drawing.overlays;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Image;
 | 
			
		||||
import java.awt.image.BufferedImage;
 | 
			
		||||
import java.io.DataInputStream;
 | 
			
		||||
 | 
			
		||||
import org.insa.graphics.drawing.Drawing.AlphaMode;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing.AlphaMode;
 | 
			
		||||
 | 
			
		||||
public class MarkerUtils {
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing.overlays;
 | 
			
		||||
package org.insa.graphs.gui.drawing.overlays;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing.overlays;
 | 
			
		||||
package org.insa.graphs.gui.drawing.overlays;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.drawing.overlays;
 | 
			
		||||
package org.insa.graphs.gui.drawing.overlays;
 | 
			
		||||
 | 
			
		||||
public interface PathOverlay extends Overlay {
 | 
			
		||||
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
package org.insa.graphics.drawing.overlays;
 | 
			
		||||
package org.insa.graphs.gui.drawing.overlays;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Point;
 | 
			
		||||
import org.insa.graphs.model.Point;
 | 
			
		||||
 | 
			
		||||
public interface PointSetOverlay extends Overlay {
 | 
			
		||||
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
package org.insa.graphics.drawing.overlays;
 | 
			
		||||
package org.insa.graphs.gui.drawing.overlays;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Point;
 | 
			
		||||
import org.insa.graphs.model.Point;
 | 
			
		||||
import org.mapsforge.core.graphics.Canvas;
 | 
			
		||||
import org.mapsforge.core.graphics.GraphicFactory;
 | 
			
		||||
import org.mapsforge.core.graphics.Style;
 | 
			
		||||
@@ -1,10 +1,11 @@
 | 
			
		||||
package org.insa.algo.shortestpath;
 | 
			
		||||
package org.insa.graphs.gui.observers;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathObserver;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public class ShortestPathGraphicObserver implements ShortestPathObserver {
 | 
			
		||||
 | 
			
		||||
@@ -1,15 +1,17 @@
 | 
			
		||||
package org.insa.algo.weakconnectivity;
 | 
			
		||||
package org.insa.graphs.gui.observers;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Node;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentObserver;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
 | 
			
		||||
public class WeaklyConnectedComponentGraphicObserver implements WeaklyConnectedComponentObserver {
 | 
			
		||||
 | 
			
		||||
    private static final Color[] COLORS = { Color.BLUE, Color.ORANGE, Color.GREEN, Color.YELLOW, Color.RED };
 | 
			
		||||
    private static final Color[] COLORS = { Color.BLUE, Color.ORANGE, Color.GREEN, Color.YELLOW,
 | 
			
		||||
            Color.RED };
 | 
			
		||||
 | 
			
		||||
    // Drawing + Graph drawing
 | 
			
		||||
    private PointSetOverlay grPoints;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.base;
 | 
			
		||||
package org.insa.graphs.gui.simple;
 | 
			
		||||
 | 
			
		||||
import java.awt.BorderLayout;
 | 
			
		||||
import java.awt.Dimension;
 | 
			
		||||
@@ -9,13 +9,13 @@ import java.io.FileInputStream;
 | 
			
		||||
import javax.swing.JFrame;
 | 
			
		||||
import javax.swing.SwingUtilities;
 | 
			
		||||
 | 
			
		||||
import org.insa.graph.Graph;
 | 
			
		||||
import org.insa.graph.Path;
 | 
			
		||||
import org.insa.graph.io.BinaryGraphReader;
 | 
			
		||||
import org.insa.graph.io.GraphReader;
 | 
			
		||||
import org.insa.graph.io.PathReader;
 | 
			
		||||
import org.insa.graphics.drawing.Drawing;
 | 
			
		||||
import org.insa.graphics.drawing.components.BasicDrawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.Drawing;
 | 
			
		||||
import org.insa.graphs.gui.drawing.components.BasicDrawing;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
import org.insa.graphs.model.io.BinaryGraphReader;
 | 
			
		||||
import org.insa.graphs.model.io.GraphReader;
 | 
			
		||||
import org.insa.graphs.model.io.PathReader;
 | 
			
		||||
 | 
			
		||||
public class Launch {
 | 
			
		||||
 | 
			
		||||
@@ -46,29 +46,28 @@ public class Launch {
 | 
			
		||||
    public static void main(String[] args) throws Exception {
 | 
			
		||||
 | 
			
		||||
        // Visit these directory to see the list of available files on Commetud.
 | 
			
		||||
        String mapName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
 | 
			
		||||
        String pathName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
 | 
			
		||||
        final String mapName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
 | 
			
		||||
        final String pathName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
 | 
			
		||||
 | 
			
		||||
        // Create a graph reader.
 | 
			
		||||
        GraphReader reader = new BinaryGraphReader(
 | 
			
		||||
        final GraphReader reader = new BinaryGraphReader(
 | 
			
		||||
                new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
 | 
			
		||||
 | 
			
		||||
        // TODO: Read the graph.
 | 
			
		||||
        Graph graph = null;
 | 
			
		||||
        final Graph graph = null;
 | 
			
		||||
 | 
			
		||||
        // Create the drawing:
 | 
			
		||||
        Drawing drawing = createDrawing();
 | 
			
		||||
        final Drawing drawing = createDrawing();
 | 
			
		||||
 | 
			
		||||
        // TODO: Draw the graph on the drawing.
 | 
			
		||||
 | 
			
		||||
        // TODO: Create a PathReader.
 | 
			
		||||
        PathReader pathReader = null;
 | 
			
		||||
        final PathReader pathReader = null;
 | 
			
		||||
 | 
			
		||||
        // TODO: Read the path.
 | 
			
		||||
        Path path = null;
 | 
			
		||||
        final Path path = null;
 | 
			
		||||
 | 
			
		||||
        // TODO: Draw the path.
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.utils;
 | 
			
		||||
package org.insa.graphs.gui.utils;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graphics.utils;
 | 
			
		||||
package org.insa.graphs.gui.utils;
 | 
			
		||||
 | 
			
		||||
import java.awt.event.ActionEvent;
 | 
			
		||||
import java.awt.event.ActionListener;
 | 
			
		||||
| 
		 Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB  | 
| 
		 Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB  | 
| 
		 Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB  | 
| 
		 Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB  | 
							
								
								
									
										14
									
								
								be-graphes-model/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						@@ -0,0 +1,14 @@
 | 
			
		||||
<?xml version="1.0"?>
 | 
			
		||||
<project
 | 
			
		||||
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
 | 
			
		||||
	xmlns="http://maven.apache.org/POM/4.0.0"
 | 
			
		||||
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 | 
			
		||||
	<modelVersion>4.0.0</modelVersion>
 | 
			
		||||
	<parent>
 | 
			
		||||
		<groupId>org.insa.graphs</groupId>
 | 
			
		||||
		<artifactId>be-graphes-all</artifactId>
 | 
			
		||||
		<version>0.0.1-SNAPSHOT</version>
 | 
			
		||||
	</parent>
 | 
			
		||||
	<artifactId>be-graphes-model</artifactId>
 | 
			
		||||
	<name>be-graphes-model</name>
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
import java.util.EnumMap;
 | 
			
		||||
import java.util.EnumSet;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Class representing a point (position) on Earth.
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph;
 | 
			
		||||
package org.insa.graphs.model;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package org.insa.graph.io;
 | 
			
		||||
package org.insa.graphs.model.io;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
@@ -21,4 +21,13 @@ public class BadFormatException extends IOException {
 | 
			
		||||
        super();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new format exception with the given message.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param message Message for the exception.
 | 
			
		||||
     */
 | 
			
		||||
    public BadFormatException(String message) {
 | 
			
		||||
        super(message);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||