seance 1
This commit is contained in:
parent
76b121ac6f
commit
b059a07cf1
2 changed files with 100 additions and 10 deletions
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# OS specific files and folders
|
||||
.DS_Store
|
||||
|
||||
# Java specific files and folders
|
||||
bin
|
||||
target
|
||||
doc
|
||||
*.jar
|
||||
.settings
|
||||
.classpath
|
||||
.vscode
|
||||
|
||||
# Editor specific files and folders
|
||||
*~
|
||||
.project
|
||||
|
||||
# Project specific files and folders
|
||||
*.mapfg
|
||||
*.mapgr
|
||||
*.path
|
||||
*.tgz
|
||||
|
|
@ -30,7 +30,22 @@ public class Path {
|
|||
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
||||
throws IllegalArgumentException {
|
||||
List<Arc> arcs = new ArrayList<Arc>();
|
||||
// TODO:
|
||||
if (nodes.size() <= 2){
|
||||
throw new IllegalArgumentException();
|
||||
}else{
|
||||
for (int j = 0; j < nodes.size(); j++){
|
||||
Node premier = nodes.get(j);
|
||||
List<Arc> suc = premier.getSuccessors();
|
||||
Arc elu = suc.get(0);
|
||||
for (int i=0; i < suc.size(); i++){
|
||||
|
||||
if ( suc.get(i).getMinimumTravelTime() <= elu.getMinimumTravelTime()){
|
||||
elu = suc.get(i);
|
||||
}
|
||||
arcs.add(elu);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Path(graph, arcs);
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +63,24 @@ public class Path {
|
|||
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
||||
throws IllegalArgumentException {
|
||||
List<Arc> arcs = new ArrayList<Arc>();
|
||||
// TODO:
|
||||
if (nodes.size() <= 2){
|
||||
throw new IllegalArgumentException();
|
||||
}else{
|
||||
for (int j = 0; j < nodes.size(); j++){
|
||||
Node premier = nodes.get(j);
|
||||
List<Arc> suc = premier.getSuccessors();
|
||||
Arc elu = suc.get(0);
|
||||
for (int i=0; i < suc.size(); i++){
|
||||
|
||||
if ( suc.get(i).getLength() <= elu.getLength()){
|
||||
elu = suc.get(i);
|
||||
}
|
||||
arcs.add(elu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new Path(graph, arcs);
|
||||
}
|
||||
|
||||
|
|
@ -187,8 +219,32 @@ public class Path {
|
|||
* @deprecated Need to be implemented.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
// TODO:
|
||||
if(this.arcs.isEmpty()){
|
||||
return true ;
|
||||
}
|
||||
if ( this.graph.getNodes().size() <= 1 ){
|
||||
return true ;
|
||||
}
|
||||
|
||||
Node origin = this.graph.getNodes().getFirst(); // à revoir ( on prend deux arcs quelconque et compare )
|
||||
List<Arc> firstSucs = origin.getSuccessors();
|
||||
List<Node> destFirstArc = new ArrayList<>() ;
|
||||
for( Arc fSuc : firstSucs){
|
||||
destFirstArc.add(fSuc.getDestination()) ;
|
||||
|
||||
}
|
||||
for (Node secondNode : destFirstArc){
|
||||
List<Arc> secondSucs = secondNode.getSuccessors();
|
||||
for (Arc sSuc : secondSucs){
|
||||
if ( sSuc.getDestination() == origin){
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,8 +254,12 @@ public class Path {
|
|||
* @deprecated Need to be implemented.
|
||||
*/
|
||||
public float getLength() {
|
||||
// TODO:
|
||||
return 0;
|
||||
float sum = 0;
|
||||
for(Arc a: this.arcs){
|
||||
sum += a.getLength();
|
||||
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -211,8 +271,12 @@ public class Path {
|
|||
* @deprecated Need to be implemented.
|
||||
*/
|
||||
public double getTravelTime(double speed) {
|
||||
// TODO:
|
||||
return 0;
|
||||
double sum = 0;
|
||||
for(Arc a: this.arcs){
|
||||
sum += a.getTravelTime(speed);
|
||||
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -223,8 +287,13 @@ public class Path {
|
|||
* @deprecated Need to be implemented.
|
||||
*/
|
||||
public double getMinimumTravelTime() {
|
||||
// TODO:
|
||||
return 0;
|
||||
double sum = 0;
|
||||
for(Arc a: this.arcs){
|
||||
sum += a.getMinimumTravelTime();
|
||||
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue