Пример #1
0
try:
    from src.gimpy import Graph, UNDIRECTED_GRAPH
except ImportError:
    from coinor.gimpy import Graph

from pulp import LpVariable, lpSum, LpProblem, LpMaximize, LpMinimize, LpConstraint
from pulp import LpStatus, value, LpBinary

node_counts = {}
numNodes = 30
numSeeds = 10
display = 'off'
for b_rule in [MOST_FRACTIONAL, INTERDICTION_BRANCHING]:
    for seed in range(numSeeds):
        G = Graph(type=UNDIRECTED_GRAPH, splines='true', K=1.5)
        G.random(numnodes=numNodes,
                 density=0.5,
                 length_range=None,
                 seedInput=seed)
        G.set_display_mode('off')

        nodes = G.get_node_list()

        T = InterdictionTree()
        T.set_display_mode(display)
        #Simple Heuristic
        IS = [-1 for i in nodes]
        for i in nodes:
            if IS[i] == -1:
                IS[i] = 1
Пример #2
0
try:
    from src.gimpy import Graph
except ImportError:
    from coinor.gimpy import Graph

if __name__ == '__main__':
    G = Graph(
        graph_type='digraph',
        splines='true',
        layout='dot2tex',
        display='pygame',
        rankdir='LR',
        fontsize='44',
        d2tgraphstyle='every text node part/.style={align=left}',
    )
    node_format = {
        #                   'height':1.0,
        #                   'width':2.0,
        #                   'fixedsize':'true',
        #                   'fontsize':'36',
        #                   'fontcolor':'red',
        'shape': 'rect',
    }

    G.add_node('0',
               label=r'C_1 = x_1 \mid x_2$ \\ $C_2 = x_2 \mid x_3',
               **node_format)
    G.add_node('1',
               label=r'C_1 = \text{TRUE}$ \\ $C_2 = x_2 \mid x_3',
               **node_format)
    G.add_node('2', label=r'C_1 = x_2$ \\ $C_2 = x_2 \mid x_3', **node_format)
Пример #3
0
Link to the video is:
http://www.youtube.com/watch?v=J0wzih3_5Wo

black: there is no flow on the arc
red  : the flow equals to the arc capacity
green: there is positive flow on the arc, less then capacity.
'''
from __future__ import print_function

try:
    from src.gimpy import Graph, DIRECTED_GRAPH
except ImportError:
    from coinor.gimpy import Graph, DIRECTED_GRAPH

if __name__ == '__main__':
    g = Graph(type=DIRECTED_GRAPH, display='off')
    g.add_node(1, pos='"0,2!"', demand=4, label='(1, 4)')

    g.add_node(3, pos='"2,4!"', demand=0)
    g.add_node(2, pos='"2,0!"', demand=0)
    g.add_node(4, pos='"4,2!"', demand=0)
    g.add_node(6, pos='"6,4!"', demand=0)

    g.add_node(5, pos='"6,0!"', demand=0)
    g.add_node(7, pos='"8,2!"', demand=-4, label='(1, -4)')
    g.add_edge(1, 3, cost=0, capacity=2, label='(0, 2)')
    g.add_edge(1, 2, cost=0, capacity=2, label='(0, 2)')
    g.add_edge(3, 4, cost=1, capacity=1, label='(1, 1)')
    g.add_edge(3, 6, cost=2, capacity=2, label='(2, 2)')
    g.add_edge(2, 4, cost=3, capacity=1, label='(3, 1)')
    g.add_edge(2, 5, cost=5, capacity=1, label='(5, 1)')
Пример #4
0
def generate_graph(seed_i, gen=None):
    '''
    Generates random directed graphs for min cost flow problem.
    '''
    if gen is not None:
        (numnodes, density, demand_numnodes, supply_numnodes, demand_range,
         cost_range, capacity_range) = gen
    g = Graph(type=DIRECTED_GRAPH, splines='true', layout='dot')
    seed(seed_i)
    for i in range(numnodes):
        for j in range(numnodes):
            if i == j:
                continue
            if (i, j) in g.edge_attr:
                continue
            if (j, i) in g.edge_attr:
                continue
            if random() < density:
                cap = randint(capacity_range[0], capacity_range[1])
                cos = randint(cost_range[0], cost_range[1])
                g.add_edge(i, j, cost=cos, capacity=cap)
    # set supply/demand
    # select random demand_numnodes many nodes
    demand_node = {}
    while len(demand_node) < demand_numnodes:
        n = randint(0, numnodes - 1)
        if n in demand_node:
            continue
        demand_node[n] = 0
    # select random supply_numnodes many nodes (different than above)
    supply_node = {}
    while len(supply_node) < supply_numnodes:
        n = randint(0, numnodes - 1)
        if n in demand_node or n in supply_node:
            continue
        supply_node[n] = 0
    # set demand amounts
    total_demand = 0
    for n in demand_node:
        demand_node[n] = randint(demand_range[0], demand_range[1])
        total_demand += demand_node[n]
    # set supply amounts
    total_supply = 0
    for n in supply_node:
        supply_node[n] = randint(demand_range[0], demand_range[1])
        total_supply += supply_node[n]
    if total_demand > total_supply:
        # this line may create random behavior, because of dictionary query
        for n in supply_node:
            excess = total_demand - total_supply
            supply_node[n] += excess
            break
    elif total_demand < total_supply:
        for n in demand_node:
            excess = total_supply - total_demand
            demand_node[n] += excess
            break
    # set demand attributes
    for n in g.get_node_list():
        if n in demand_node:
            g.get_node(n).set_attr('demand', -1 * demand_node[n])
        elif n in supply_node:
            g.get_node(n).set_attr('demand', supply_node[n])
        else:
            g.get_node(n).set_attr('demand', 0)
    return g
Пример #5
0
try:
    from src.gimpy import Graph
except:
    from coinor.gimpy import Graph

if __name__ == '__main__':
    G = Graph(
        type='digraph',
        splines='true',
        layout='dot',
        display='xdot',
        rankdir='LR',
        label='ISE Requirements and Prerequisite Map',
        fontsize='120',
        labelloc='t',
        size="7.5,10.0!",
        ratio='fill',
        esep='10',
        ranksep='1.8',
    )
    node_format = {
        #                   'height':1.0,
        #                   'width':2.0,
        #                   'fixedsize':'true',
        'fontsize': '60',
        #                   'fontcolor':'red',
        'shape': 'ellipse',
        'style': 'bold',
        'fontname': 'Times-Bold'
    }