def pruner_bakeoff(nPoints, nSeeds, r0, delta, spread, lumpage, outputNameRoot):
    """
    Generate a graph, then use all the CANDIDATE_PRUNERS to prune it, and save the results for later investigation.
    """
    from spiralPointDistribution import spiralPointDistribution
    from pointsToOutwardDigraph import graphFromPoints
    #import matplotlib.pyplot as plot
    #import matplotlib.tri as tri    
    import pygraph.readwrite.dot as dotIO
    
    points = spiralPointDistribution(nPoints, nSeeds, r0, delta, spread, lumpage)
    
    outdir = os.path.dirname(outputNameRoot)
    if not os.path.exists(outdir):
        os.makedirs(outdir)
    
    #x, y = zip(*points)
    #plot.figure()
    #plot.gca().set_aspect('equal')
    #plot.triplot(tri.Triangulation(x, y), 'r,:')
    #plot.scatter(x, y)
    #plot.show()
    
    #NOT YET FINISHED
    #save png as outputNameRoot.prunerName.png (once I get Python graphviz bindings working)
    
    for pruner in CANDIDATE_PRUNERS:
        graph = graphFromPoints(points, nSeeds)
        graph = friendly_rename(graph)
        graph = pruner.prune(graph)
        dotstring = dotIO.write(graph)
        dotname = "{0}.{1}.gv".format(outputNameRoot, pruner.__class__.__name__)
        with open(dotname, "w") as dotfile:
            dotfile.write(dotstring)
def buildRandomModel(
    nPoints,
    nSeeds,
    r0,
    delta,
    spread,
    lumpage,
    behaviorPaths,
    pruner,
    prunerPaths=None,
    name_prefix="",
    bonus_identity=3,
):
    """
    Builds a running, randomly-generated network model from the given parameters.
    
    Parameters:
        nPoints - Number of nodes that should be in the resulting network, including seed points.
        nSeeds - Number of nodes that are "seeds"- have an in-degree of 0. Must be at least 1.
        r0 - A parameter that defines how strongly the first few nodes shape the graph. Large values will result in more separation between generators.
        delta - A parameter that, in practice, defines how quickly distances grow. Leads to fewer edges as the graph goes further down.
        spread - A parameter that affects how many "clusters" the graph will eventually wind up with.
        lumpage - An integer that affects how aggressively points cluster. 0 will result in a graph of a random scattering of points, but
                  otherwise low values result in stricter clusters.
        behaviorPaths - A list of strings representing file paths that yapsy should search for IModelBehavior plugins.
        pruner - either a pointsToOutwardDigraph.IPruneEdges to use to prune the graph to its final form,
                 or the name of a plugin implementing IPruneEdges that can be loaded for the purpose.
        prunerPaths - Ignored if pruner is not a string. If pruner is a string, that pruner, as the name of a Yapsy plugin,
                      will be searched for in these paths.
        namePrefix - Prefix for all node names (inserted after @ for non-generator nodes). Used when welding multiple graphs.
        bonus_identiy - Number of additional times to add the IdentityBehavior to the pool of IModelBehavior that
                        is drawn from for noise functions. Used to increase the odds that a column will not be
                        intentionally semi-randomized or modified before presentation to the column printer.
                        Use 0 to keep standard equal probabilities.
    """
    points = spiralPointDistribution.spiralPointDistribution(nPoints, nSeeds, r0, delta, spread, lumpage)
    rawCompleteGraph = pointsToOutwardDigraph.graphFromPoints(points, nSeeds)
    rawCompleteGraph = pointsToOutwardDigraph.friendly_rename(rawCompleteGraph, name_prefix)
    if isinstance(pruner, str):
        # TODO: fix
        candidatePruners = pointsToOutwardDigraph.prunerImplementations(prunerPaths)
        for pluginInfo in candidatePruners:
            if pluginInfo.name == pruner:
                pruner = pluginInfo.plugin_object
                pruner.activate()
                break
        raise ValueError("No pruner by name {0} found in specified paths.".format(pruner))
    trimmedGraph = pruner.prune(rawCompleteGraph)

    function_plugins = modelBehaviorImplementations(behaviorPaths)
    functions = [plugin.plugin_object for plugin in function_plugins]
    return workingModelFromPygraph(trimmedGraph, functions, bonus_identity)
def buildRandomModel(nPoints, nSeeds, r0, delta, spread, lumpage, behaviorPaths, pruner, prunerPaths = None, name_prefix="", bonus_identity = 3):
    """
    Builds a running, randomly-generated network model from the given parameters.
    
    Parameters:
        nPoints - Number of nodes that should be in the resulting network, including seed points.
        nSeeds - Number of nodes that are "seeds"- have an in-degree of 0. Must be at least 1.
        r0 - A parameter that defines how strongly the first few nodes shape the graph. Large values will result in more separation between generators.
        delta - A parameter that, in practice, defines how quickly distances grow. Leads to fewer edges as the graph goes further down.
        spread - A parameter that affects how many "clusters" the graph will eventually wind up with.
        lumpage - An integer that affects how aggressively points cluster. 0 will result in a graph of a random scattering of points, but
                  otherwise low values result in stricter clusters.
        behaviorPaths - A list of strings representing file paths that yapsy should search for IModelBehavior plugins.
        pruner - either a pointsToOutwardDigraph.IPruneEdges to use to prune the graph to its final form,
                 or the name of a plugin implementing IPruneEdges that can be loaded for the purpose.
        prunerPaths - Ignored if pruner is not a string. If pruner is a string, that pruner, as the name of a Yapsy plugin,
                      will be searched for in these paths.
        namePrefix - Prefix for all node names (inserted after @ for non-generator nodes). Used when welding multiple graphs.
        bonus_identiy - Number of additional times to add the IdentityBehavior to the pool of IModelBehavior that
                        is drawn from for noise functions. Used to increase the odds that a column will not be
                        intentionally semi-randomized or modified before presentation to the column printer.
                        Use 0 to keep standard equal probabilities.
    """
    points = spiralPointDistribution.spiralPointDistribution(nPoints, nSeeds, r0, delta, spread, lumpage)
    rawCompleteGraph = pointsToOutwardDigraph.graphFromPoints(points, nSeeds)
    rawCompleteGraph = pointsToOutwardDigraph.friendly_rename(rawCompleteGraph, name_prefix)
    if isinstance(pruner, str):
        #TODO: fix
        candidatePruners = pointsToOutwardDigraph.prunerImplementations(prunerPaths)
        for pluginInfo in candidatePruners:
            if pluginInfo.name == pruner:
                pruner = pluginInfo.plugin_object
                pruner.activate()
                break
        raise ValueError("No pruner by name {0} found in specified paths.".format(pruner))
    trimmedGraph = pruner.prune(rawCompleteGraph)
    
    function_plugins =modelBehaviorImplementations(behaviorPaths)
    functions = [plugin.plugin_object for plugin in function_plugins]
    return workingModelFromPygraph(trimmedGraph, functions, bonus_identity)
def pruner_bakeoff(nPoints, nSeeds, r0, delta, spread, lumpage,
                   outputNameRoot):
    """
    Generate a graph, then use all the CANDIDATE_PRUNERS to prune it, and save the results for later investigation.
    """
    from spiralPointDistribution import spiralPointDistribution
    from pointsToOutwardDigraph import graphFromPoints
    #import matplotlib.pyplot as plot
    #import matplotlib.tri as tri
    import pygraph.readwrite.dot as dotIO

    points = spiralPointDistribution(nPoints, nSeeds, r0, delta, spread,
                                     lumpage)

    outdir = os.path.dirname(outputNameRoot)
    if not os.path.exists(outdir):
        os.makedirs(outdir)

    #x, y = zip(*points)
    #plot.figure()
    #plot.gca().set_aspect('equal')
    #plot.triplot(tri.Triangulation(x, y), 'r,:')
    #plot.scatter(x, y)
    #plot.show()

    #NOT YET FINISHED
    #save png as outputNameRoot.prunerName.png (once I get Python graphviz bindings working)

    for pruner in CANDIDATE_PRUNERS:
        graph = graphFromPoints(points, nSeeds)
        graph = friendly_rename(graph)
        graph = pruner.prune(graph)
        dotstring = dotIO.write(graph)
        dotname = "{0}.{1}.gv".format(outputNameRoot,
                                      pruner.__class__.__name__)
        with open(dotname, "w") as dotfile:
            dotfile.write(dotstring)