first dijkstra

这个提交包含在:
Lacroix Raphael 2022-04-15 10:23:13 +02:00
父节点 53957f25cc
当前提交 7fa1212e70
共有 25 个文件被更改,包括 444 次插入3 次删除

查看文件

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

查看文件

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

21
.idea/compiler.xml 普通文件
查看文件

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="be-graphes-gui" />
<module name="be-graphes-model" />
<module name="be-graphes-algos" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="be-graphes-algos" target="1.11" />
<module name="be-graphes-all" target="1.11" />
<module name="be-graphes-gui" target="1.11" />
<module name="be-graphes-model" target="1.11" />
</bytecodeTargetLevel>
</component>
</project>

9
.idea/encodings.xml 普通文件
查看文件

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/be-graphes-algos/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/be-graphes-gui/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/be-graphes-gui/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/be-graphes-model/src/main/java" charset="UTF-8" />
</component>
</project>

25
.idea/jarRepositories.xml 普通文件
查看文件

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jitpack.io" />
<option name="name" value="jitpack.io" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.github.blackears:svgSalamander:v1.1.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/github/blackears/svgSalamander/v1.1.1/svgSalamander-v1.1.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/github/blackears/svgSalamander/v1.1.1/svgSalamander-v1.1.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/github/blackears/svgSalamander/v1.1.1/svgSalamander-v1.1.1-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: junit:junit:4.12">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: net.sf.kxml:kxml2:2.3.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.apache.ant:ant:1.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/ant/ant/1.8.1/ant-1.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/ant/ant/1.8.1/ant-1.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/ant/ant/1.8.1/ant-1.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.apache.ant:ant-launcher:1.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/ant/ant-launcher/1.8.1/ant-launcher-1.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/ant/ant-launcher/1.8.1/ant-launcher-1.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/ant/ant-launcher/1.8.1/ant-launcher-1.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.hamcrest:hamcrest-core:1.3">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.mapsforge:mapsforge-core:0.13.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-core/0.13.0/mapsforge-core-0.13.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-core/0.13.0/mapsforge-core-0.13.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-core/0.13.0/mapsforge-core-0.13.0-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.mapsforge:mapsforge-map:0.13.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map/0.13.0/mapsforge-map-0.13.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map/0.13.0/mapsforge-map-0.13.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map/0.13.0/mapsforge-map-0.13.0-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.mapsforge:mapsforge-map-awt:0.13.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map-awt/0.13.0/mapsforge-map-awt-0.13.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map-awt/0.13.0/mapsforge-map-awt-0.13.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map-awt/0.13.0/mapsforge-map-awt-0.13.0-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.mapsforge:mapsforge-map-reader:0.13.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map-reader/0.13.0/mapsforge-map-reader-0.13.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map-reader/0.13.0/mapsforge-map-reader-0.13.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-map-reader/0.13.0/mapsforge-map-reader-0.13.0-sources.jar!/" />
</SOURCES>
</library>
</component>

查看文件

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.mapsforge:mapsforge-themes:0.13.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-themes/0.13.0/mapsforge-themes-0.13.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-themes/0.13.0/mapsforge-themes-0.13.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/mapsforge/mapsforge-themes/0.13.0/mapsforge-themes-0.13.0-sources.jar!/" />
</SOURCES>
</library>
</component>

10
.idea/misc.xml 普通文件
查看文件

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
</project>

11
.idea/modules.xml 普通文件
查看文件

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/be-graphes-algos/be-graphes-algos.iml" filepath="$PROJECT_DIR$/be-graphes-algos/be-graphes-algos.iml" />
<module fileurl="file://$PROJECT_DIR$/be-graphes-all.iml" filepath="$PROJECT_DIR$/be-graphes-all.iml" />
<module fileurl="file://$PROJECT_DIR$/be-graphes-gui/be-graphes-gui.iml" filepath="$PROJECT_DIR$/be-graphes-gui/be-graphes-gui.iml" />
<module fileurl="file://$PROJECT_DIR$/be-graphes-model/be-graphes-model.iml" filepath="$PROJECT_DIR$/be-graphes-model/be-graphes-model.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml 普通文件
查看文件

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

查看文件

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="be-graphes-model" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>

查看文件

@ -1,5 +1,17 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.algorithm.AbstractSolution;
import org.insa.graphs.algorithm.utils.BinaryHeap;
import org.insa.graphs.algorithm.utils.Label;
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 java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
public DijkstraAlgorithm(ShortestPathData data) {
@ -9,8 +21,76 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
@Override
protected ShortestPathSolution doRun() {
final ShortestPathData data = getInputData();
Graph gr = data.getGraph();
// array containing all the labels
Label[] labels = new Label[gr.size()];
//initialization of the labels
int i = 0;
for (Node l : gr.getNodes()){
labels[i] = new Label(l, false, null);
i++;
}
// initialization of the heap & the first node
BinaryHeap<Label> pQueue = new BinaryHeap<Label>();
labels[data.getOrigin().getId()].setCost(0);
pQueue.insert(labels[data.getOrigin().getId()]);
boolean found = false;
// Pathfinding
while(!pQueue.isEmpty() && !found){
Label labelX = pQueue.findMin();
pQueue.deleteMin();
labelX.setMarked(true);
found = (data.getDestination() == labelX.getCurrNode());
for (Arc y : labelX.getCurrNode().getSuccessors()){
Label labelY = labels[y.getDestination().getId()];
if (!labelY.isMarked()){
if (labelY.getCost() > labelX.getCost()+data.getCost(y)){
labelY.setCost(
labelX.getCost()+data.getCost(y)
);
pQueue.insert(labelY);
labelY.setFather(y); // we give the arc from x to y as the "father arc"
}
}
}
}
ShortestPathSolution solution = null;
// TODO:
// Destination has no predecessor, the solution is infeasible...
if (labels[data.getDestination().getId()] == null) {
solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
}
else {
// The destination has been found, notify the observers.
notifyDestinationReached(data.getDestination());
// Create the path from the array of predecessors...
ArrayList<Arc> arcs = new ArrayList<>();
Arc arc = labels[data.getDestination().getId()].getFather();
while (arc != null) {
arcs.add(arc);
arc = labels[arc.getOrigin().getId()].getFather();
}
// Reverse the path...
Collections.reverse(arcs);
// Create the final solution.
solution = new ShortestPathSolution(data, AbstractSolution.Status.OPTIMAL, new Path(gr, arcs));
}
return solution;
}

查看文件

@ -1,7 +1,57 @@
package org.insa.graphs.algorithm.utils;
import org.insa.graphs.model.*;
public class Label {
public class Label implements Comparable<Label> {
private Node currNode;
private boolean marked;
private double cost;
private Arc father;
public Label(Node currNode, boolean marked, Arc father){
this.currNode = currNode;
this.marked = marked;
this.cost = Double.POSITIVE_INFINITY;
this.father = father;
}
public double getCost(){
return(this.cost);
}
public Node getCurrNode() {
return currNode;
}
public Arc getFather() {
return father;
}
public boolean isMarked() {
return marked;
}
public void setCost(double cost) {
this.cost = cost;
}
public void setFather(Arc father) {
this.father = father;
}
public void setMarked(boolean marked) {
this.marked = marked;
}
public int compareTo(Label other) {
if (this.cost < other.getCost()) {
return -1;
} else {
if (this.cost > other.getCost()) {
return 1;
} else {
return 0;
}
}
}
}

14
be-graphes-all.iml 普通文件
查看文件

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>

查看文件

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="be-graphes-model" />
<orderEntry type="module" module-name="be-graphes-algos" />
<orderEntry type="library" name="Maven: net.sf.kxml:kxml2:2.3.0" level="project" />
<orderEntry type="library" name="Maven: org.mapsforge:mapsforge-themes:0.13.0" level="project" />
<orderEntry type="library" name="Maven: org.mapsforge:mapsforge-map:0.13.0" level="project" />
<orderEntry type="library" name="Maven: org.mapsforge:mapsforge-core:0.13.0" level="project" />
<orderEntry type="library" name="Maven: org.mapsforge:mapsforge-map-awt:0.13.0" level="project" />
<orderEntry type="library" name="Maven: com.github.blackears:svgSalamander:v1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.ant:ant:1.8.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.ant:ant-launcher:1.8.1" level="project" />
<orderEntry type="library" name="Maven: org.mapsforge:mapsforge-map-reader:0.13.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>

查看文件

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>