Exemple #1
0
    def __init__(self, *args, **kwargs):
        # callback functions can be passed to class constructor as keyword
        # arguments
        self.branch_method = kwargs.pop('branch_method', None)
        self.post_process_branch = kwargs.pop('post_process_branch', None)
        self.post_process_node = kwargs.pop('post_process_node', None)
        self.relaxed_solver = kwargs.pop('relaxed_solver', None)
        self.is_solution_feasible = kwargs.pop('is_solution_feasible', None)
        self.generate_cuts = kwargs.pop('generate_cuts', None)
        self.generate_cuts_from_node = kwargs.pop('generate_cuts_from_node',
                                                  None)
        self.heuristics = kwargs.pop('heuristics', None)
        self.init_vars = kwargs.pop('init_vars', None)
        self.display_mode = kwargs.pop('display_mode', 'off')
        self.display_interval = kwargs.pop('display_interval', 1)
        self.layout = kwargs.pop('layout', 'dot')
        self.svg_prefix = kwargs.pop('svg_prefix', 'tree')

        if self.display_mode != 'off':
            if not gimpy_installed:
                print("GiMPy not installed. Display mode set to 'off'")
                self.display_mode = 'off'
            else:
                if grumpy_installed:
                    self.Tree = BBTree()
                else:
                    if self.layout == 'bak':
                        print(
                            "GrUMPy not installed. Display mode set to 'off'")
                        self.display_mode = 'off'
                    else:
                        self.Tree = BinaryTree()
        if self.display_mode != 'off':
            self.Tree.set_display_mode(self.display_mode)
            self.Tree.set_layout(self.layout)

        super(DipProblem, self).__init__(*args, **kwargs)
        self._subproblem = []
        self.relaxation = RelaxationCollection(self)
Exemple #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)
    CONSTRAINTS, VARIABLES, OBJ, MAT, RHS = GenerateRandomMIP(
        numVars=numVars , numCons=numCons,rand_seed= rand_seed)
    
    I = identity(len(VARIABLES))
    negI = negIdentity(len(VARIABLES))
    RHS = RHS + [0]*len(VARIABLES) + [3]*len(VARIABLES)
    for i in VARIABLES:
        MAT[i] = MAT[i] + negI[int(i[1:])]
        CONSTRAINTS.append('C'+str(len(CONSTRAINTS)))
    for i in VARIABLES:
        MAT[i] = MAT[i] + I[int(i[1:])]
        CONSTRAINTS.append('C'+str(len(CONSTRAINTS)))
        
    for i in branch:
        for j in search:
            T = BBTree()
            opt, LB,stat = BranchAndBound(
                T, CONSTRAINTS, VARIABLES, OBJ,MAT, RHS,branch_strategy=i,search_strategy=j,
                more_return = True,binary_vars = False)
            if LB>-INFINITY:
                costs_node[i + ' - ' + j] = np.append(costs_node[i + ' - ' + j],int(stat['Size']))
                costs_time[i + ' - ' + j] = np.append(costs_time[i + ' - ' + j],float(stat['Time']))
                costs_lp[i + ' - ' + j] = np.append(costs_lp[i + ' - ' + j],int(stat['LP Solved']))
            else:
                costs_node[i + ' - ' + j] = np.append(costs_node[i + ' - ' + j],INFINITY)
                costs_time[i + ' - ' + j] = np.append(costs_time[i + ' - ' + j],INFINITY)
                costs_lp[i + ' - ' + j] = np.append(costs_lp[i + ' - ' + j],INFINITY)
                
                
def performance_profile(costs,name):
    # Do some computations
Exemple #4
0
    from coinor.grumpy import BBTree, gexf_installed
    grumpy_installed = True
except ImportError:
    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')
Exemple #5
0
    BEST_FIRST: "bestfirst",
    BEST_ESTIMATE: "bestestimate"
}

# test problem, (num_vars,num_cons,seed)
problem = [(10, 10, 0), (10, 10, 1), (10, 10, 2), (10, 10, 3), (20, 10, 4),
           (20, 10, 5), (20, 10, 6), (20, 10, 7), (30, 20, 8), (30, 20, 9),
           (30, 20, 10), (30, 20, 11), (40, 20, 12), (40, 20, 13),
           (40, 30, 14)]
# number of LPs solved for each problem
num_lp = {}

if __name__ == '__main__':
    for p in problem:
        var, con, seed = p
        bt = BBTree()
        CONSTRAINTS, VARIABLES, OBJ, MAT, RHS = bt.GenerateRandomMIP(
            numVars=var, numCons=con, rand_seed=seed)
        num_lp[p] = {}
        for b in branch_strategy:
            for s in search_strategy:
                # create a new object before each branch and bound call
                bt = BBTree()
                # solve using BB
                solution, bb_optimal = bt.BranchAndBound(CONSTRAINTS,
                                                         VARIABLES,
                                                         OBJ,
                                                         MAT,
                                                         RHS,
                                                         branch_strategy=b,
                                                         search_strategy=s)
Exemple #6
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()
Exemple #7
0
    from coinor.grumpy import BBTree, gexf_installed
    grumpy_installed = True
except ImportError:
    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)
Exemple #8
0
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
from coinor.grumpy import BBTree
import sys
import io

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
    for line in sys.stdin:
        bt.ProcessLine(line)
        print('line', line_number, 'processed.')
        line_number = line_number+1
        if line_number%10 != 0:
            continue
        bt.display_all()
Exemple #9
0
    T._lp_count = lp_count

    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,
Exemple #10
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
    for line in sys.stdin:
        bt.ProcessLine(line)
        print 'line', line_number, 'processed.'
        line_number = line_number + 1
        if line_number % 10 != 0:
            continue
        bt.display_all()
Exemple #11
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()
Exemple #12
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)
Exemple #13
0
from future import standard_library
standard_library.install_aliases()
from builtins import str
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())