Beispiel #1
0
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
                for j in G.get_neighbors(i):
                    IS[j] = 0

        T._incumbent_value = sum(IS)
        print 'Heuristic solution value: ', T._incumbent_value
Beispiel #2
0
    G.add_node('5',
               label=r'C_1 = \text{TRUE}$ \\ $C_2 = \text{TRUE}',
               color='green',
               **node_format)
    G.add_node('6',
               label=r'C_1 = \text{FALSE}$ \\ $C_2 = x_3',
               color='red',
               **node_format)
    G.add_node('9',
               label=r'C_1 = \text{TRUE}$ \\ $C_2 = \text{TRUE}',
               color='green',
               **node_format)
    G.add_node('10',
               label=r'C_1 = \text{FALSE}$ \\ $C_2 = \text{FALSE}',
               color='red',
               **node_format)
    G.add_edge('0', '1', label=r'x_1 = \text{TRUE}')
    G.add_edge('0', '2', label=r'x_1 = \text{FALSE}')
    G.add_edge('1', '3', label=r'x_2 = \text{TRUE}')
    G.add_edge('1', '4', label=r'x_2 = \text{FALSE}')
    G.add_edge('2', '5', label=r'x_2 = \text{TRUE}')
    G.add_edge('2', '6', label=r'x_2 = \text{FALSE}')
    G.add_edge('4', '9', label=r'x_3 = \text{TRUE}')
    G.add_edge('4', '10', label=r'x_3 = \text{FALSE}')

    G.set_display_mode('xdot')

    print(G)

    G.display(basename='Turing')
Beispiel #3
0
    cluster_attrs = {'fontsize' : '72'} #, 'style' : 'bold'}

    cluster_attrs.update({'name': 'Tracks', 'label': 'Choose One'})    
    G.create_cluster(['ISE 172', 'ISE 215/216'], cluster_attrs)

    cluster_attrs.update({'name':'English', 'label':'English Requirements'})    
    G.create_cluster(['Engl 1', 'Engl 2'], cluster_attrs)

    cluster_attrs.update({'name': 'Eng', 'label':'Engineering Electives\nChoose At Least Four'})
    G.create_cluster(['Mech 2/3', 'ME 104', 'ECE 83/81', 'CEE 170', 'Chem 44', 
                      'CSE 17', 'Mat 33'], cluster_attrs)

    cluster_attrs.update({'name':'Isolated', 'label':'Miscellaneous Requirements'})
    G.create_cluster(['Eng 5', 'Chem 30', 'Eco 1', 'Acct 108', 'ISE 154'], cluster_attrs)

    cluster_attrs.update({'name':'TE', 
                          'label':'Technical Electives\nChoose at Least 4\n(at Least 2 ISE)'})
    G.create_cluster(['ISE 339', 'ISE 316', 'ISE 347', 'ISE 275', 'ISE 358', 'ISE 324', 
                      'ISE 332', 'ISE 362', 'ISE 341', 'ISE 356', 'ISE 355', 'ISE 321', 
                      'ISE 345', 'ISE 382', 'ISE 334', 'ISE 372', 'ISE 319', 'ISE 340', 
                      'ISE 344', 'CSE 2xx', 'Math 251', 'BIS 3xx', 'CSE 3xx', 'Math 230',
                      'ISE 156'], 
                     cluster_attrs)

    cluster_attrs.update({'name':'Computing', 'label':'Computing Requirements'})
    G.create_cluster(['CSE 2', 'Eng 10', 'ISE 112'], cluster_attrs)

    G.set_display_mode('xdot')

    G.display(basename = 'ISERequirements', format = 'pdf')
Beispiel #4
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)')
    g.add_edge(4, 6, cost=1, capacity=3, label='(1, 3)')
    g.add_edge(4, 7, cost=4, capacity=2, label='(4, 2)')
    g.add_edge(4, 5, cost=1, capacity=1, label='(3, 1)')
    g.add_edge(6, 7, cost=0, capacity=2, label='(0, 2)')
    g.add_edge(5, 7, cost=0, capacity=2, label='(0, 2)')
    g.set_display_mode('pygame')
    g.display()

    #    g.cycle_canceling('pygame')
    g.min_cost_flow(algo='cycle_canceling')
    #    g.max_flow(1, 7)

    nl = list(int(n) for n in g.get_node_list())
    nl.sort()
    for n in nl:
        for m in nl:
            if g.check_edge(n, m):
                print(n, m, g.get_edge_attr(n, m, 'flow'))
Beispiel #5
0
try:
    from src.gimpy import Graph, UNDIRECTED_GRAPH
except ImportError:
    from coinor.gimpy import Graph, UNDIRECTED_GRAPH

G = Graph(type = UNDIRECTED_GRAPH, splines = 'true', K = 1.5)
G.random(numnodes = 10, Euclidean = True, seedInput = 11, 
         #add_labels = True,
         #scale = 10,
         #scale_cost = 10,
         #degree_range = (2, 4),
         #length_range = (1, 10)
         )
G.set_display_mode('pygame')
G.display()
#G.dfs(0)
G.search(0, display = 'pygame', algo = 'Dijkstra')