# Path: Dip/src/dippy/examples/bpp/bin_pack_func.py
# class BinPackProb(object):
#     def __init__(self, ITEMS, volume, capacity):
#         self.ITEMS = ITEMS
#         self.volume = volume
#         self.BINS = list(range(len(ITEMS))) # Create 1 bin for each
#                                       # item, indices start at 0
#         self.capacity = capacity
# 
# def formulate(bpp, args):
# 
#     prob = DipProblem("Bin Packing")
# 
#     assign_vars = LpVariable.dicts("x",
#                                    [(i, j) for i in bpp.BINS
#                                     for j in bpp.ITEMS],
#                                    cat=LpBinary)
#     use_vars    = LpVariable.dicts("y", bpp.BINS, cat=LpBinary)
#     waste_vars  = LpVariable.dicts("w", bpp.BINS, 0, None)
# 
#     prob += lpSum(waste_vars[i] for i in bpp.BINS), "min_waste"
# 
#     for j in bpp.ITEMS:
#         prob += lpSum(assign_vars[i, j] for i in bpp.BINS) == 1
# 
#     for i in bpp.BINS:
#         prob.relaxation[i] += (lpSum(bpp.volume[j] * assign_vars[i, j]
#                                 for j in bpp.ITEMS) + waste_vars[i] 
#                                 == bpp.capacity * use_vars[i])
# 
#     for i in bpp.BINS:
#         for j in bpp.ITEMS:
#             prob.relaxation[i] += assign_vars[i, j] <= use_vars[i]
# 
#     if args.antisymmetryCutsBins:
#         for m in range(0, len(bpp.BINS) - 1):
#             prob += use_vars[bpp.BINS[m]] >= use_vars[bpp.BINS[m + 1]]
# 
#     if args.antisymmetryCutsItems:
#         for m in range(0, len(bpp.BINS)):
#             for n in range(0, len(bpp.ITEMS)):
#                 if m > n:
#                     i = bpp.BINS[m]
#                     j = bpp.ITEMS[n]
#                     prob += assign_vars[i, j] == 0
# 
#     # Attach the problem data and variable dictionaries
#     # to the DipProblem 
#     prob.bpp         = bpp
#     prob.assign_vars = assign_vars
#     prob.use_vars    = use_vars
#     prob.waste_vars  = waste_vars
#     prob.tol = pow(pow(2, -24), old_div(2.0, 3.0))
# 
#     return prob
# 
# def solve(prob, args):
# 
#     prob.root_heuristic = False
#     prob.node_heuristic = False
#     if args.branchingRule != 'Default':
#         prob.branch_method = my_branch
#         prob.branching_rule = args.branchingRule
#     if args.rootHeuristic:
#         prob.heuristics = my_heuristics
#         prob.is_root_node = True
#         prob.root_heuristic = True
#     if args.nodeHeuristic:
#         prob.heuristics = my_heuristics
#         prob.is_root_node = True
#         prob.node_heuristic = True
#   
#     dippyOpts = addDippyOpts(args)
# 
#     status, message, primals, duals = Solve(prob, dippyOpts)
#   
#     if status == LpStatusOptimal:
#         return dict((var, var.value()) for var in prob.variables())
#     else:
#         return None


from past.utils import old_div
from .bin_pack_func import BinPackProb, formulate, solve
import sys
#!/usr/bin/env python

from __future__ import division
from __future__ import print_function
from __future__ import absolute_import


if __name__ == '__main__':
    # Python starts here
    bpp = BinPackProb(ITEMS  = [1, 2, 3, 4, 5, 6],
                      volume = {1: 2, 2: 5, 3: 3, 4: 3, 5: 3, 6: 2},
                      capacity = 9)
  
    prob = formulate(bpp)
  
    prob.tol = pow(pow(2, -24), old_div(2.0, 3.0))
    if len(sys.argv) > 1:
        xopt = solve(prob, sys.argv[1])
    else:

# Path: Dip/src/dippy/examples/bpp/bin_pack_func.py
# class BinPackProb(object):
#     def __init__(self, ITEMS, volume, capacity):
#         self.ITEMS = ITEMS
#         self.volume = volume
#         self.BINS = list(range(len(ITEMS))) # Create 1 bin for each
#                                       # item, indices start at 0
#         self.capacity = capacity
# 
# def formulate(bpp, args):
# 
#     prob = DipProblem("Bin Packing")
# 
#     assign_vars = LpVariable.dicts("x",
#                                    [(i, j) for i in bpp.BINS
#                                     for j in bpp.ITEMS],
#                                    cat=LpBinary)
#     use_vars    = LpVariable.dicts("y", bpp.BINS, cat=LpBinary)
#     waste_vars  = LpVariable.dicts("w", bpp.BINS, 0, None)
# 
#     prob += lpSum(waste_vars[i] for i in bpp.BINS), "min_waste"
# 
#     for j in bpp.ITEMS:
#         prob += lpSum(assign_vars[i, j] for i in bpp.BINS) == 1
# 
#     for i in bpp.BINS:
#         prob.relaxation[i] += (lpSum(bpp.volume[j] * assign_vars[i, j]
#                                 for j in bpp.ITEMS) + waste_vars[i] 
#                                 == bpp.capacity * use_vars[i])
# 
#     for i in bpp.BINS:
#         for j in bpp.ITEMS:
#             prob.relaxation[i] += assign_vars[i, j] <= use_vars[i]
# 
#     if args.antisymmetryCutsBins:
#         for m in range(0, len(bpp.BINS) - 1):
#             prob += use_vars[bpp.BINS[m]] >= use_vars[bpp.BINS[m + 1]]
# 
#     if args.antisymmetryCutsItems:
#         for m in range(0, len(bpp.BINS)):
#             for n in range(0, len(bpp.ITEMS)):
#                 if m > n:
#                     i = bpp.BINS[m]
#                     j = bpp.ITEMS[n]
#                     prob += assign_vars[i, j] == 0
# 
#     # Attach the problem data and variable dictionaries
#     # to the DipProblem 
#     prob.bpp         = bpp
#     prob.assign_vars = assign_vars
#     prob.use_vars    = use_vars
#     prob.waste_vars  = waste_vars
#     prob.tol = pow(pow(2, -24), old_div(2.0, 3.0))
# 
#     return prob
# 
# def solve(prob, args):
# 
#     prob.root_heuristic = False
#     prob.node_heuristic = False
#     if args.branchingRule != 'Default':
#         prob.branch_method = my_branch
#         prob.branching_rule = args.branchingRule
#     if args.rootHeuristic:
#         prob.heuristics = my_heuristics
#         prob.is_root_node = True
#         prob.root_heuristic = True
#     if args.nodeHeuristic:
#         prob.heuristics = my_heuristics
#         prob.is_root_node = True
#         prob.node_heuristic = True
#   
#     dippyOpts = addDippyOpts(args)
# 
#     status, message, primals, duals = Solve(prob, dippyOpts)
#   
#     if status == LpStatusOptimal:
#         return dict((var, var.value()) for var in prob.variables())
#     else:
#         return None


# Path: Dip/src/dippy/examples/bpp/bin_pack_instance2.py
from past.utils import old_div
from .bin_pack_func import BinPackProb, formulate, solve
import sys

#!/usr/bin/env python

from __future__ import division
from __future__ import print_function
from __future__ import absolute_import


if __name__ == '__main__':
    # Python starts here
    bpp = BinPackProb(ITEMS  = [1, 2, 3, 4, 5, 6],
                      volume = {1: 2, 2: 5, 3: 3, 4: 3, 5: 3, 6: 2},
                      capacity = 9)
  
    prob = formulate(bpp)
  
    prob.tol = pow(pow(2, -24), old_div(2.0, 3.0))
    if len(sys.argv) > 1:
        xopt = solve(prob, sys.argv[1])
    else:

        xopt = solve(prob)