Skip to content

Commit

Permalink
Merge pull request #75 from JavierMarrero/development-JavierMarrero
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
JavierMarrero committed Nov 20, 2022
2 parents ccc2a76 + fedaa7d commit 098938e
Show file tree
Hide file tree
Showing 10 changed files with 1,211 additions and 1,137 deletions.
85 changes: 41 additions & 44 deletions src/cu/edu/cujae/graphy/algorithms/EulerianCycleDetection.java
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;
}

}
Loading

0 comments on commit 098938e

Please sign in to comment.