Exemplo n.º 1
0
    grumpy_installed = False

from coinor.blimpy import PriorityQueue
from random import random, randint, seed

display_mode = 'xdot'
layout = 'dot'
display_interval = 100
if not grumpy_installed:
    layout = 'dot'

if layout == 'bak' and grumpy_installed:
    T = BBTree()
else:
    T = BinaryTree()
T.set_display_mode(display_mode)
T.set_layout(layout)

'''
#Add key
C = Cluster(graph_name = 'Key', label = 'Key', fontsize = '12')
C.add_node('C', label = 'Candidate', style = 'filled', color = 'yellow', fillcolor = 'yellow')
C.add_node('I', label = 'Infeasible', style = 'filled', color = 'orange', fillcolor = 'orange')
C.add_node('S', label = 'Solution', style = 'filled', color = 'lightblue', fillcolor = 'lightblue')
C.add_node('P', label = 'Pruned', style = 'filled', color = 'red', fillcolor = 'red')
C.add_edge('C', 'I', style = 'invisible', arrowhead = 'none')
C.add_edge('I', 'S', style = 'invisible', arrowhead = 'none')
C.add_edge('S', 'P', style = 'invisible', arrowhead = 'none')
T.add_subgraph(C)
'''
Exemplo n.º 2
0
from future import standard_library
standard_library.install_aliases()
from builtins import str
try:
    from coinor.grumpy import BBTree
except ImportError:
    from src.grumpy import BBTree
import sys
import io
from PIL import Image as PIL_Image

bt = BBTree()
bt.set_display_mode('pygame')
line_number = 1
file_ = open('p0201_GLPK.vbc', 'r')
#for line in sys.stdin:
for line in file_:
    bt.ProcessLine(line)
    #To print out snapshots of the tree
    if line_number % 100000 != 0:
        continue
    imagefile = open('tree-' + str(line_number) + '.png', 'w')
    imagefile.write(bt.GenerateTreeImage())
    imagefile.close()

#gnuplot_image = bt.GenerateHistogram()
gnuplot_image = io.StringIO(bt.GenerateTreeImage())
#gnuplot_image = bt.GenerateScatterplot()
#gnuplot_image = bt.GenerateIncumbentPath()
#gnuplot_image = bt.GenerateForecastImages()
im = PIL_Image.open(gnuplot_image)
Exemplo n.º 3
0
from coinor.grumpy import BBTree
import sys
import StringIO

try:
    from PIL import Image as PIL_Image
except ImportError:
    PIL_INSTALLED = False
else:
    PIL_INSTALLED = True

if __name__ == '__main__':
    bt = BBTree()
    bt.set_display_mode('pygame')
    line_number = 0
#    file_ = open('air04.bak', 'r')
    for line in sys.stdin:
#    for line in file_:
        bt.ProcessLine(line)
        print 'line', line_number, 'processed.'
        line_number = line_number+1
        if line_number%10000 != 0:
            continue
#        imagefile = open('tree-'+str(line_number)+'.png','w')
#        imagefile.write(bt.GenerateTreeImage())
#        imagefile.close()
        if bt.root is not None:
#            gnuplot_image = bt.GenerateHistogram()
            gnuplot_image = StringIO.StringIO(bt.GenerateTreeImage())
#            gnuplot_image = bt.GenerateScatterplot()
#            gnuplot_image = bt.GenerateIncumbentPath()
Exemplo n.º 4
0
    grumpy_installed = False

from coinor.blimpy import PriorityQueue
from random import random, randint, seed

display_mode = 'xdot'
layout = 'dot'
display_interval = 100
if not grumpy_installed:
    layout = 'dot'

if layout == 'bak' and grumpy_installed:
    T = BBTree()
else:
    T = BinaryTree()
T.set_display_mode(display_mode)
T.set_layout(layout)
'''
#Add key
C = Cluster(graph_name = 'Key', label = 'Key', fontsize = '12')
C.add_node('C', label = 'Candidate', style = 'filled', color = 'yellow', fillcolor = 'yellow')
C.add_node('I', label = 'Infeasible', style = 'filled', color = 'orange', fillcolor = 'orange')
C.add_node('S', label = 'Solution', style = 'filled', color = 'lightblue', fillcolor = 'lightblue')
C.add_node('P', label = 'Pruned', style = 'filled', color = 'red', fillcolor = 'red')
C.add_edge('C', 'I', style = 'invisible', arrowhead = 'none')
C.add_edge('I', 'S', style = 'invisible', arrowhead = 'none')
C.add_edge('S', 'P', style = 'invisible', arrowhead = 'none')
T.add_subgraph(C)
'''

T.add_node('C',
Exemplo n.º 5
0
    if more_return:
        stat = {'Time': timer, 'Size': node_count, 'LP Solved': lp_count}
        if branch_strategy == RELIABILITY_BRANCHING:
            stat['LP Solved for Bounds'] = lp_count - full_solved
            stat['Halfly Solved'] = half_solved
            stat['Fully Solved'] = full_solved
        return opt, LB, stat
    
    return opt, LB


if __name__ == '__main__':
    from generator import GenerateRandomMIP
    T = BBTree()
    T.set_display_mode('xdot')
    CONSTRAINTS, VARIABLES, OBJ, MAT, RHS = GenerateRandomMIP(numVars=30, numCons=20, rand_seed=418, density=0.3)
    _, _, stat1 = BranchAndBound(T, CONSTRAINTS, VARIABLES, OBJ, MAT, RHS,
                                 branch_strategy=RELIABILITY_BRANCHING,
                                 search_strategy=DEPTH_FIRST,
                                 display_interval=10000,
                                 solver='primalSimplex',
                                 binary_vars=True,
                                 more_return=True
                                 )
    T = BBTree()
    T.set_display_mode('xdot')
    _, _, stat2 = BranchAndBound(T, CONSTRAINTS, VARIABLES, OBJ, MAT, RHS,
                                 branch_strategy=PSEUDOCOST_BRANCHING,
                                 search_strategy=DEPTH_FIRST,
                                 display_interval=10000,
Exemplo n.º 6
0
from coinor.grumpy import BBTree

bt = BBTree()
file = open('vbc.out', 'r')
for line in file:
    bt.ProcessLine(line)

bt.set_display_mode('file')
bt.display()
Exemplo n.º 7
0
import coinor.grumpy.examples
try:
    from coinor.grumpy import BBTree
except ImportError:
    from src.grumpy import BBTree
from inspect import getfile
from os.path import join, dirname
import sys
import io

bt = BBTree()
line_number = 0
#for line in sys.stdin:
instance = join(dirname(getfile(coinor.grumpy.examples)), 'p0201_GLPK.vbc')
with open(instance, 'r') as file_:
    bt.set_display_mode('file')
    for line in file_:
        line_number += 1
        bt.ProcessLine(line)
        #To print out snapshots of the tree
        if line_number % 100 != 0:
            continue
        bt.display('tree', 'tree-' + str(line_number))

#bt.write_image(bt.GenerateHistogram())
bt.set_display_mode('matplotlib')
bt.display('tree')
#bt.write_image(bt.GenerateScatterplot())
#bt.write_image(bt.GenerateIncumbentPath())
#bt.write_image(bt.GenerateForecastImages())