-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from JavierMarrero/development-JavierMarrero
Bugfix
- Loading branch information
Showing
10 changed files
with
1,211 additions
and
1,137 deletions.
There are no files selected for viewing
85 changes: 41 additions & 44 deletions
85
src/cu/edu/cujae/graphy/algorithms/EulerianCycleDetection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
package cu.edu.cujae.graphy.algorithms; | ||
/** | ||
* @author César Férnandez García | ||
* Esta clase permite ver si existe al menos un Ciclo Euleriano | ||
* */ | ||
import cu.edu.cujae.graphy.core.Graph; | ||
|
||
/** | ||
* Esta clase permite ver si existe al menos un ciclo de Euler. | ||
* | ||
* @author César Férnandez García | ||
*/ | ||
import cu.edu.cujae.graphy.core.Graph; | ||
import cu.edu.cujae.graphy.core.iterators.GraphIterator; | ||
|
||
public class EulerianCycleDetection<V> extends AbstractAlgorithm<Boolean> { | ||
|
||
private final Graph<V> graph; | ||
|
||
public EulerianCycleDetection(Graph<V> graph) { | ||
super(true); | ||
this.graph = graph; | ||
} | ||
@Override | ||
public Algorithm<Boolean> apply() { | ||
//esta funcion lo que hace es ver si deja de cumplirse la paridad de los grados de los nodos | ||
boolean isOdd = false; | ||
GraphIterator<V> iterator = (GraphIterator<V>) graph.depthFirstSearchIterator(true); | ||
while(!isOdd && iterator.hasNext()) { | ||
iterator.next(); | ||
int numberOfEdges = iterator.getAllAdjacentEdges().size(); | ||
if( (numberOfEdges == 0) || ( (numberOfEdges % 2) == 1) ) { | ||
isOdd=true; | ||
} | ||
|
||
|
||
} | ||
if(isOdd) { | ||
setResult(!isOdd); | ||
} | ||
|
||
return this; | ||
} | ||
public Graph<V> getGraph() { | ||
return graph; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
public class EulerianCycleDetection<V> extends AbstractAlgorithm<Boolean> | ||
{ | ||
|
||
private final Graph<V> graph; | ||
|
||
public EulerianCycleDetection(Graph<V> graph) | ||
{ | ||
super(true); | ||
this.graph = graph; | ||
} | ||
|
||
@Override | ||
public Algorithm<Boolean> apply() | ||
{ | ||
//esta funcion lo que hace es ver si deja de cumplirse la paridad de los grados de los nodos | ||
boolean isOdd = false; | ||
GraphIterator<V> iterator = (GraphIterator<V>) graph.depthFirstSearchIterator(false); | ||
while (!isOdd && iterator.hasNext()) | ||
{ | ||
iterator.next(); | ||
int numberOfEdges = iterator.getAllAdjacentEdges().size(); | ||
if ((numberOfEdges == 0) || ((numberOfEdges % 2) != 0)) | ||
{ | ||
isOdd = true; | ||
} | ||
|
||
} | ||
if (isOdd) | ||
{ | ||
setResult(!isOdd); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
} |
Oops, something went wrong.