Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix #75

Merged
merged 3 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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