Esempio n. 1
0
def solveNetworkGP(N, edgeCosts, edgeMaxFlows, sources, sinks):
    m = Flow(N)
    m.substitutions.update({
        'edgeCost': edgeCosts,
        'edgeMaxFlow': edgeMaxFlows,
        'source': sources,
        'sink': sinks,
    })
    m.substitutions.update({'slackCost':
                            1000})  #['sweep',np.linspace(100,10000,10)]})
    m.cost = np.sum(
        m['edgeCost'] * m['flow']) + m['slackCost'] * np.prod(m['slack'])
    m = relaxed_constants(m)
    sol = m.localsolve(verbosity=4, reltol=10**-5, iteration_limit=100)
    return sol
Esempio n. 2
0
    #     sources[0]   = N-1
    #     sinks        = np.zeros(N)
    #     sinks[1:]    = 1.

    # GP and LP Solutions

    m = Flow(N)
    m.substitutions.update({
        'edgeCost': edgeCosts,
        'edgeMaxFlow': edgeMaxFlows,
        'source': sources,
        'sink': sinks,
    })
    m.substitutions.update({'slackCost':
                            1000})  #['sweep',np.linspace(100,10000,10)]})
    m.cost = np.sum(
        m['edgeCost'] * m['flow']) + m['slackCost'] * np.prod(m['slack'])
    m = relaxed_constants(m)
    solGP = m.localsolve(verbosity=3)
    solLP = solveNetworkLP(N, edgeCosts, edgeMaxFlows, sources, sinks)

    # solGP = solveNetworkGP(N,edgeCosts,edgeMaxFlows,sources,sinks)
    # solLP = solveNetworkLP(N,edgeCosts,edgeMaxFlows,sources,sinks)

    # Flow comparison
    flowGP = np.round(solGP('flow'), 3)
    connectivityGP = np.round(solGP('connectivity'), 3)
    flowLP = np.round(solLP['flow'], 3)
    #connectivityLP =

    # Plotting
    g = drawNetwork(solGP, points=pointDict)
Esempio n. 3
0
    #     sinks        = np.zeros(N)
    #     sinks[1:]    = 1.

    # GP and LP Solutions

    m = Flow(N)
    m.substitutions.update({
        'edgeCost': edgeCosts,
        'edgeMaxFlow': edgeMaxFlows,
        'source': sources,
        'sink': sinks,
    })
    m.substitutions.update({'slackCost':
                            50})  # ['sweep',np.linspace(100,10000,10)]})
    m.cost = np.sum(m['edgeCost'] * m['flow']) * (
        1 + m['slackCost'] * np.prod(m['slackOne']) * np.prod(m['slackTwo'])
    )  # + 10000*np.prod(m['slackOne']) + 10000*np.prod(m['slackTwo'])
    # m = relaxed_constants(m)
    solGP = m.localsolve(verbosity=3, reltol=1e-8, iteration_limit=500)
    solLP = solveNetworkLP(N, edgeCosts, edgeMaxFlows, sources, sinks)

    # solGP = solveNetworkGP(N,edgeCosts,edgeMaxFlows,sources,sinks)
    # solLP = solveNetworkLP(N,edgeCosts,edgeMaxFlows,sources,sinks)

    # Flow comparison
    # flowGP = np.round(solGP('flow'), 3)
    # connectivityGP = np.round(solGP('connectivity'), 3)
    # flowLP = np.round(solLP['flow'], 3)
    # connectivityLP =

    # Plotting