jlowenz / hypergraphdb

Automatically exported from code.google.com/p/hypergraphdb
0 stars 0 forks source link

Depth cut off in HGBreadthFirstTraversal does not work #75

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
HGBreadthFirstTraversal bfsTraversal =
                new HGBreadthFirstTraversal(handle, new                    SimpleALGenerator(graph), 3);

Trying to do a BFS on the graph with a depth cut-off, does not work.

This is because the maxDistance attribute of the class which is initialized to 
the depth passed in the constructor, is overridden in the init method. Please 
see the code snippet below - 

public HGBreadthFirstTraversal(HGHandle startAtom, HGALGenerator 
adjListGenerator, int maxDistance)
    {
        this.maxDistance = maxDistance; // INITIALIZED HERE
        this.startAtom = startAtom;
        this.adjListGenerator = adjListGenerator;
        init();

    }

private void init()
    {
        this.maxDistance = Integer.MAX_VALUE;   //OVERRIDDEN HERE    
        examined.put(startAtom, Boolean.TRUE);
        advance(startAtom, 0);          
        initialized = true;        
    }

So checks in the advance method does not work. 

private void advance(HGHandle from, int distance)
    {
        if (distance >= maxDistance) //maxDistance is always Integer.MAX_VALUE
            return;
Please fix this. 

The maxDistance attribute can be declared as final and initialised once in the 
constructor. It need not be assigned in init.

What version of the product are you using? On what operating system?

Version 1.1 on windows 7

Original issue reported on code.google.com by rath.swa...@gmail.com on 13 Jun 2012 at 10:34

GoogleCodeExporter commented 9 years ago
That has been fixed in 1.2, thanks for reporting it!
Boris

Original comment by borislav...@gmail.com on 15 Jun 2012 at 4:14