示例#1
0
def example():
    J,v = multidict({1:16, 2:19, 3:23, 4:28})
    a = {(1,1):2,    (1,2):3,    (1,3):4,    (1,4):5,
         (2,1):3000, (2,2):3500, (2,3):5100, (2,4):7200,
         }
    I,b = multidict({1:7, 2:10000})
    return I,J,v,a,b
示例#2
0
def make_inst():
    """make_inst: prepare data for the diet model"""
    F,c,d = multidict({       # cost # composition
        "CQPounder":  [ 360, {"Cal":556, "Carbo":39, "Protein":30,
                              "VitA":147,"VitC": 10, "Calc":221, "Iron":2.4}],
        "Big Mac"  :  [ 320, {"Cal":556, "Carbo":46, "Protein":26,
                              "VitA":97, "VitC":  9, "Calc":142, "Iron":2.4}],
        "FFilet"   :  [ 270, {"Cal":356, "Carbo":42, "Protein":14,
                              "VitA":28, "VitC":  1, "Calc": 76, "Iron":0.7}],
        "Chicken"  :  [ 290, {"Cal":431, "Carbo":45, "Protein":20,
                              "VitA": 9, "VitC":  2, "Calc": 37, "Iron":0.9}],
        "Fries"    :  [ 190, {"Cal":249, "Carbo":30, "Protein": 3,
                              "VitA": 0, "VitC":  5, "Calc":  7, "Iron":0.6}],
        "Milk"     :  [ 170, {"Cal":138, "Carbo":10, "Protein": 7,
                              "VitA":80, "VitC":  2, "Calc":227, "Iron": 0}],
        "VegJuice" :  [ 100, {"Cal": 69, "Carbo":17, "Protein": 1,
                              "VitA":750,"VitC":  2, "Calc":18,  "Iron": 0}],
        })

    N,a,b = multidict({       # min,max intake
        "Cal"     : [ 2000,  3000],
        "Carbo"   : [  300,  375 ],
        "Protein" : [   50,   60 ],
        "VitA"    : [  500,  750 ],
        "VitC"    : [   85,  100 ],
        "Calc"    : [  660,  900 ],
        "Iron"    : [  6.0,  7.5 ],
     })

    return F, N, a, b, c, d
示例#3
0
def make_data():
    I, d = multidict({0: 80, 1: 270, 2: 250, 3: 160, 4: 180})  # demand
    J, M, f = multidict({
        0: [500, 1000],
        1: [500, 1000],
        2: [500, 1000]
    })  # capacity, fixed costs
    c = {
        (0, 0): 4,
        (0, 1): 6,
        (0, 2): 9,  # transportation costs
        (1, 0): 5,
        (1, 1): 4,
        (1, 2): 7,
        (2, 0): 6,
        (2, 1): 3,
        (2, 2): 4,
        (3, 0): 8,
        (3, 1): 5,
        (3, 2): 3,
        (4, 0): 10,
        (4, 1): 8,
        (4, 2): 4,
    }
    return I, J, d, M, f, c
示例#4
0
文件: diet.py 项目: fserra/PySCIPOpt
def make_inst():
    """make_inst: prepare data for the diet model"""
    F,c,d = multidict({       # cost # composition
        "QPounder" :  [ 1.84, {"Cal":510, "Carbo":34, "Protein":28,
                               "VitA":15, "VitC":  6, "Calc":30, "Iron":20}],
        "McLean"   :  [ 2.19, {"Cal":370, "Carbo":35, "Protein":24, "VitA":15,
                               "VitC": 10, "Calc":20, "Iron":20}],
        "Big Mac"  :  [ 1.84, {"Cal":500, "Carbo":42, "Protein":25,
                               "VitA": 6, "VitC":  2, "Calc":25, "Iron":20}],
        "FFilet"   :  [ 1.44, {"Cal":370, "Carbo":38, "Protein":14,
                               "VitA": 2, "VitC":  0, "Calc":15, "Iron":10}],
        "Chicken"  :  [ 2.29, {"Cal":400, "Carbo":42, "Protein":31,
                               "VitA": 8, "VitC": 15, "Calc":15, "Iron": 8}],
        "Fries"    :  [  .77, {"Cal":220, "Carbo":26, "Protein": 3,
                               "VitA": 0, "VitC": 15, "Calc": 0, "Iron": 2}],
        "McMuffin" :  [ 1.29, {"Cal":345, "Carbo":27, "Protein":15,
                               "VitA": 4, "VitC":  0, "Calc":20, "Iron":15}],
        "1% LFMilk":  [  .60, {"Cal":110, "Carbo":12, "Protein": 9,
                               "VitA":10, "VitC":  4, "Calc":30, "Iron": 0}],
        "OrgJuice" :  [  .72, {"Cal": 80, "Carbo":20, "Protein": 1,
                               "VitA": 2, "VitC":120, "Calc": 2, "Iron": 2}],
        })

    N,a,b = multidict({       # min,max intake
        "Cal"     : [ 2000,  None ],
        "Carbo"   : [  350,  375 ],
        "Protein" : [   55,  None ],
        "VitA"    : [  100,  None ],
        "VitC"    : [  100,  None ],
        "Calc"    : [  100,  None ],
        "Iron"    : [  100,  None ],
     })

    return F,N,a,b,c,d
示例#5
0
def make_inst():
    """make_inst: prepare data for the diet model"""
    F,c,d = multidict({       # cost # composition
        "CQPounder":  [ 360, {"Cal":556, "Carbo":39, "Protein":30,
                              "VitA":147,"VitC": 10, "Calc":221, "Iron":2.4}],
        "Big Mac"  :  [ 320, {"Cal":556, "Carbo":46, "Protein":26,
                              "VitA":97, "VitC":  9, "Calc":142, "Iron":2.4}],
        "FFilet"   :  [ 270, {"Cal":356, "Carbo":42, "Protein":14,
                              "VitA":28, "VitC":  1, "Calc": 76, "Iron":0.7}],
        "Chicken"  :  [ 290, {"Cal":431, "Carbo":45, "Protein":20,
                              "VitA": 9, "VitC":  2, "Calc": 37, "Iron":0.9}],
        "Fries"    :  [ 190, {"Cal":249, "Carbo":30, "Protein": 3,
                              "VitA": 0, "VitC":  5, "Calc":  7, "Iron":0.6}],
        "Milk"     :  [ 170, {"Cal":138, "Carbo":10, "Protein": 7,
                              "VitA":80, "VitC":  2, "Calc":227, "Iron": 0}],
        "VegJuice" :  [ 100, {"Cal": 69, "Carbo":17, "Protein": 1,
                              "VitA":750,"VitC":  2, "Calc":18,  "Iron": 0}],
        })

    N,a,b = multidict({       # min,max intake
        "Cal"     : [ 2000,  3000],
        "Carbo"   : [  300,  375 ],
        "Protein" : [   50,   60 ],
        "VitA"    : [  500,  750 ],
        "VitC"    : [   85,  100 ],
        "Calc"    : [  660,  900 ],
        "Iron"    : [  6.0,  7.5 ],
     })

    return F,N,a,b,c,d
示例#6
0
def make_inst():
    """make_inst: prepare data for the diet model"""
    F,c,d = multidict({       # cost # composition
        "QPounder" :  [ 1.84, {"Cal":510, "Carbo":34, "Protein":28,
                               "VitA":15, "VitC":  6, "Calc":30, "Iron":20}],
        "McLean"   :  [ 2.19, {"Cal":370, "Carbo":35, "Protein":24, "VitA":15,
                               "VitC": 10, "Calc":20, "Iron":20}],
        "Big Mac"  :  [ 1.84, {"Cal":500, "Carbo":42, "Protein":25,
                               "VitA": 6, "VitC":  2, "Calc":25, "Iron":20}],
        "FFilet"   :  [ 1.44, {"Cal":370, "Carbo":38, "Protein":14,
                               "VitA": 2, "VitC":  0, "Calc":15, "Iron":10}],
        "Chicken"  :  [ 2.29, {"Cal":400, "Carbo":42, "Protein":31,
                               "VitA": 8, "VitC": 15, "Calc":15, "Iron": 8}],
        "Fries"    :  [  .77, {"Cal":220, "Carbo":26, "Protein": 3,
                               "VitA": 0, "VitC": 15, "Calc": 0, "Iron": 2}],
        "McMuffin" :  [ 1.29, {"Cal":345, "Carbo":27, "Protein":15,
                               "VitA": 4, "VitC":  0, "Calc":20, "Iron":15}],
        "1% LFMilk":  [  .60, {"Cal":110, "Carbo":12, "Protein": 9,
                               "VitA":10, "VitC":  4, "Calc":30, "Iron": 0}],
        "OrgJuice" :  [  .72, {"Cal": 80, "Carbo":20, "Protein": 1,
                               "VitA": 2, "VitC":120, "Calc": 2, "Iron": 2}],
        })

    N,a,b = multidict({       # min,max intake
        "Cal"     : [ 2000,  None ],
        "Carbo"   : [  350,  375 ],
        "Protein" : [   55,  None ],
        "VitA"    : [  100,  None ],
        "VitC"    : [  100,  None ],
        "Calc"    : [  100,  None ],
        "Iron"    : [  100,  None ],
     })

    return F, N, a, b, c, d
示例#7
0
def make_data():
    """creates example data set"""
    I, d = multidict({1: 80, 2: 270, 3: 250, 4: 160, 5: 180})  # demand
    J, M, f = multidict({
        1: [500, 1000],
        2: [500, 1000],
        3: [500, 1000]
    })  # capacity, fixed costs
    c = {
        (1, 1): 4,
        (1, 2): 6,
        (1, 3): 9,  # transportation costs
        (2, 1): 5,
        (2, 2): 4,
        (2, 3): 7,
        (3, 1): 6,
        (3, 2): 3,
        (3, 3): 4,
        (4, 1): 8,
        (4, 2): 5,
        (4, 3): 3,
        (5, 1): 10,
        (5, 2): 8,
        (5, 3): 4,
    }
    return I, J, d, M, f, c
示例#8
0
def make_inst2():
    I,d = multidict({1:45, 2:20, 3:30 , 4:30}) # demand
    J,M = multidict({1:35, 2:50, 3:40})        # capacity
    c = {(1,1):8,    (1,2):9,    (1,3):14  ,   # {(customer,factory) : cost<float>}
         (2,1):6,    (2,2):12,   (2,3):9   ,
         (3,1):10,   (3,2):13,   (3,3):16  ,
         (4,1):9,    (4,2):7,    (4,3):5   ,
         }
    return I,J,c,d,M
示例#9
0
def make_inst2():
    I,d = multidict({1:45, 2:20, 3:30 , 4:30}) # demand
    J,M = multidict({1:35, 2:50, 3:40})        # capacity
    c = {(1,1):8,    (1,2):9,    (1,3):14  ,   # {(customer,factory) : cost<float>}
         (2,1):6,    (2,2):12,   (2,3):9   ,
         (3,1):10,   (3,2):13,   (3,3):16  ,
         (4,1):9,    (4,2):7,    (4,3):5   ,
         }
    return I,J,c,d,M
示例#10
0
def make_inst1():
    I,d = multidict({1:80, 2:270, 3:250 , 4:160, 5:180}) # demand
    J,M = multidict({1:500, 2:500, 3:500})               # capacity
    c = {(1,1):4,    (1,2):6,    (1,3):9,  # cost
         (2,1):5,    (2,2):4,    (2,3):7,
         (3,1):6,    (3,2):3,    (3,3):4,
         (4,1):8,    (4,2):5,    (4,3):3,
         (5,1):10,   (5,2):8,    (5,3):4,
         }
    return I,J,c,d,M
示例#11
0
def make_data():
    I,d = multidict({1:80, 2:270, 3:250, 4:160, 5:180})            # demand
    J,M,f = multidict({1:[500,1000], 2:[500,1000], 3:[500,1000]}) # capacity, fixed costs
    c = {(1,1):4,  (1,2):6,  (1,3):9,    # transportation costs
         (2,1):5,  (2,2):4,  (2,3):7,
         (3,1):6,  (3,2):3,  (3,3):4,
         (4,1):8,  (4,2):5,  (4,3):3,
         (5,1):10, (5,2):8,  (5,3):4,
         }
    return I,J,d,M,f,c
示例#12
0
def make_data():
    a = { (1,1):.25, (1,2):.15, (1,3):.2,
          (2,1):.3,  (2,2):.3,  (2,3):.1,
          (3,1):.15, (3,2):.65, (3,3):.05,
          (4,1):.1,  (4,2):.05,  (4,3):.8
          }
    epsilon = 0.01
    I,p = multidict({1:5, 2:6, 3:8, 4:20})
    K,LB = multidict({1:.2, 2:.3, 3:.2})
    return I,K,a,p,epsilon,LB
示例#13
0
def make_data():
    """creates example data set"""
    a = { (1,1):.25, (1,2):.15, (1,3):.2,
          (2,1):.3,  (2,2):.3,  (2,3):.1,
          (3,1):.15, (3,2):.65, (3,3):.05,
          (4,1):.1,  (4,2):.05,  (4,3):.8
          }
    epsilon = 0.01
    I,p = multidict({1:5, 2:6, 3:8, 4:20})
    K,LB = multidict({1:.2, 2:.3, 3:.2})
    return I,K,a,p,epsilon,LB
示例#14
0
def make_inst1():
	I,d=multidict({1:80,2:270,3:250,4:160,5:100}) 	# demand
	J,M=multidict({1:500,2:500,3:500}) 				# capacity
	c={
		(1,1):4,    (1,2):6,    (1,3):9,  # const
     	(2,1):5,    (2,2):4,    (2,3):7,
     	(3,1):6,    (3,2):3,    (3,3):3,
     	(4,1):8,    (4,2):5,    (4,3):3,
     	(5,1):10,   (5,2):8,    (5,3):4,
     	}
	return I,J,c,d,M
示例#15
0
def example():
    I,d = multidict({1:80, 2:270, 3:250, 4:160, 5:180})                # demand
    J,M,f = multidict({10:[500,100], 11:[500,100], 12:[500,100]})     # capacity, fixed costs
    c = {(1,10):4,  (1,11):6,  (1,12):9,           # transportation costs
         (2,10):5,  (2,11):4,  (2,12):7,
         (3,10):6,  (3,11):3,  (3,12):4,
         (4,10):8,  (4,11):5,  (4,12):3,
         (5,10):10, (5,11):8,  (5,12):4,
         }
    x_pos = {1:0, 2:0, 3:0, 4:0, 5:0, 10:2, 11:2, 12:2}    # positions of the points in the plane
    y_pos = {1:2, 2:1, 3:0, 4:-1, 5:-2, 10:1, 11:0, 12:-1}
    return I,J,d,M,f,c,x_pos,y_pos
示例#16
0
def make_inst1():
    """creates example data set 1"""
    d = {(1,1):80,   (1,2):85,   (1,3):300,  (1,4):6, # {(customer,commodity):demand}}
         (2,1):270,  (2,2):160,  (2,3):400,  (2,4):7,
         (3,1):250,  (3,2):130,  (3,3):350,  (3,4):4,
         (4,1):160,  (4,2):60,   (4,3):200,  (4,4):3,
         (5,1):180,  (5,2):40,   (5,3):150,  (5,4):5
         }
    I = set([i for (i,k) in d])
    K = set([k for (i,k) in d])
    J,M = multidict({1:3000, 2:3000, 3:3000})  # capacity

    produce = {1:[2,4], 2:[1,2,3], 3:[2,3,4]}  # products that can be produced in each facility
    weight = {1:5, 2:2, 3:3, 4:4}              # {commodity: weight}
    cost = {(1,1):4,  (1,2):6, (1,3):9,        # {(customer,factory): cost}
            (2,1):5,  (2,2):4, (2,3):7,
            (3,1):6,  (3,2):3, (3,3):4,
            (4,1):8,  (4,2):5, (4,3):3,
            (5,1):10, (5,2):8, (5,3):4
            }
    c = {}
    for i in I:
        for j in J:
            for k in produce[j]:
                c[i,j,k] = cost[i,j] * weight[k]

    return I,J,K,c,d,M
示例#17
0
def point_set_example_a():
    return multidict({
        0: (0, 0),
        0.33: (1.56, -0.167),
        0.67: (2.22, -1),
        1: (2, -2.5)
    })
示例#18
0
def make_2r():
    """creates example data set 2"""
    J, p = multidict({       # jobs, processing times
        1 : 2,
        2 : 2,
        3 : 3,
        4 : 2,
        5 : 5,
        })
    P = [(1,2), (1,3), (2,4)]
    R = [1,2]
    T = 6
    c = {}
    for j in J:
        for t in range(1,T-p[j]+2):
            c[j,t] = 1*(t-1+p[j])
    a = {
        # resource 1:
        (1,1,0):2, (1,1,1):2,
        (2,1,0):1, (2,1,1):1,
        (3,1,0):1, (3,1,1):1, (3,1,2):1,
        (4,1,0):1, (4,1,1):1,
        (5,1,0):0, (5,1,1):0, (5,1,2):1, (5,1,3):0, (5,1,4):0,
        # resource 2:
        (1,2,0):1, (1,2,1):0,
        (2,2,0):1, (2,2,1):1,
        (3,2,0):0, (3,2,1):0, (3,2,2):0,
        (4,2,0):1, (4,2,1):2,
        (5,2,0):1, (5,2,1):2, (5,2,2):1, (5,2,3):1, (5,2,4):1,
        }
    RUB = {(1,1):2, (1,2):2, (1,3):2, (1,4):2, (1,5):2, (1,6):2, (1,7):2,
           (2,1):2, (2,2):2, (2,3):2, (2,4):2, (2,5):2, (2,6):2, (2,7):2 }
    return (J,P,R,T,p,c,a,RUB)
示例#19
0
def make_1r():
    J, p = multidict({  # jobs, processing times
        1: 1,
        2: 3,
        3: 2,
        4: 2,
    })
    P = [(1, 2), (1, 3), (2, 4)]
    R = [1]
    T = 6
    c = {}
    for j in J:
        for t in range(1, T - p[j] + 2):
            c[j, t] = 1 * (t - 1 + p[j])
    a = {
        (1, 1, 0): 2,
        (2, 1, 0): 2,
        (2, 1, 1): 1,
        (2, 1, 2): 1,
        (3, 1, 0): 1,
        (3, 1, 1): 1,
        (4, 1, 0): 1,
        (4, 1, 1): 2,
    }
    RUB = {(1, 1): 2, (1, 2): 2, (1, 3): 1, (1, 4): 2, (1, 5): 2, (1, 6): 2}
    return (J, P, R, T, p, c, a, RUB)
示例#20
0
def make_data_trick():
    T = 7               # number of periods
    N = 5               # number of working periods of each staff element in a cycle
    J = range(4)        # shift set; 0 == rest
    S = [2,3]           # subset of shifts that must be kept at least consecutive days
    # staff set, base cost
    I,c_base = multidict({1:8000, 2:9000, 3:10000, 4:11000, 5:12000, 6:13000, 7:14000, 8:15000})
    c = {}
    for i in I:
        for t in range(1,T+1):
            for j in J:
                if j == 0:
                    continue
                c[i,t,j] = c_base[i]
                if j == 3:      # night shift, more expensive
                    c[i,t,j] *= 2
                if t == T-1 or t == T:    # weekend, more expensive
                    c[i,t,j] *= 1.5
    b = {
        (1,1):2, (1,2):2, (1,3):2,
        (2,1):2, (2,2):2, (2,3):2,
        (3,1):2, (3,2):2, (3,3):2,
        (4,1):2, (4,2):2, (4,3):2,
        (5,1):2, (5,2):2, (5,3):2,
        (6,1):2, (6,2):2, (6,3):2,
        (7,1):2, (7,2):2, (7,3):2,
        }
    return I,T,N,J,S,c,b
示例#21
0
def make_inst1():
    d = {(1,1):80,   (1,2):85,   (1,3):300,  (1,4):6, # {(customer,commodity):demand}}
         (2,1):270,  (2,2):160,  (2,3):400,  (2,4):7,
         (3,1):250,  (3,2):130,  (3,3):350,  (3,4):4,
         (4,1):160,  (4,2):60,   (4,3):200,  (4,4):3,
         (5,1):180,  (5,2):40,   (5,3):150,  (5,4):5
         }
    I = set([i for (i,k) in d])
    K = set([k for (i,k) in d])
    J,M = multidict({1:3000, 2:3000, 3:3000})  # capacity

    produce = {1:[2,4], 2:[1,2,3], 3:[2,3,4]}  # products that can be produced in each facility
    weight = {1:5, 2:2, 3:3, 4:4}              # {commodity: weight}
    cost = {(1,1):4,  (1,2):6, (1,3):9,        # {(customer,factory): cost}
            (2,1):5,  (2,2):4, (2,3):7,
            (3,1):6,  (3,2):3, (3,3):4,
            (4,1):8,  (4,2):5, (4,3):3,
            (5,1):10, (5,2):8, (5,3):4
            }
    c = {}
    for i in I:
        for j in J:
            for k in produce[j]:
                c[i,j,k] = cost[i,j] * weight[k]

    return I,J,K,c,d,M
示例#22
0
def make_data_trick():
    T = 7               # number of periods
    N = 5               # number of working periods of each staff element in a cycle
    J = range(4)        # shift set; 0 == rest
    S = [2,3]           # subset of shifts that must be kept at least consecutive days
    # staff set, base cost
    I,c_base = multidict({1:8000, 2:9000, 3:10000, 4:11000, 5:12000, 6:13000, 7:14000, 8:15000})
    c = {}
    for i in I:
        for t in range(1,T+1):
            for j in J:
                if j == 0:
                    continue
                c[i,t,j] = c_base[i]
                if j == 3:      # night shift, more expensive
                    c[i,t,j] *= 2
                if t == T-1 or t == T:    # weekend, more expensive
                    c[i,t,j] *= 1.5
    b = {
        (1,1):2, (1,2):2, (1,3):2,
        (2,1):2, (2,2):2, (2,3):2,
        (3,1):2, (3,2):2, (3,3):2,
        (4,1):2, (4,2):2, (4,3):2,
        (5,1):2, (5,2):2, (5,3):2,
        (6,1):2, (6,2):2, (6,3):2,
        (7,1):2, (7,2):2, (7,3):2,
        }
    return I,T,N,J,S,c,b
示例#23
0
def mk_example():
    """mk_example: book example for the single item lot sizing"""
    T = 5
    _,f,c,d,h = multidict({
        1 :  [3,1,5,1],
        2 :  [3,1,7,1],
        3 :  [3,3,3,1],
        4 :  [3,3,6,1],
        5 :  [3,3,4,1],
        })

    return T,f,c,d,h
示例#24
0
def mk_example():
    """mk_example: book example for the single item lot sizing"""
    T = 5
    _,f,c,d,h = multidict({
        1 :  [3,1,5,1],
        2 :  [3,1,7,1],
        3 :  [3,3,3,1],
        4 :  [3,3,6,1],
        5 :  [3,3,4,1],
        })

    return T,f,c,d,h
示例#25
0
def solve():
    file_name = 'Database.xlsx'

    # OGRANICZENIA

    # Ilosc sztuk danego produktow K (wszystkich) w J magazynie
    #J,M = multidict({'Magazyn 1': 3000, 'Magazyn 2': 3000, 'Magazyn 3':3000})
    J, M = multidict(load_data(file_name, 'PojemnoscMagazynu'))
    # Jakie produkty sa dostepne w J magazynie
    produkt = load_data(file_name, 'DostepnoscProduktowWMagazynach')
    print(produkt)

    # Zapotrzebowanie J klienta na K produktu
    d = load_data(file_name, 'Zapotrzebowanie')

    # Lista sklepow
    I = set([i for (i, k) in d])

    # Lista produktow
    K = set([k for (i, k) in d])
    print(produkt)
    # Wagi produktow
    waga = load_data(file_name, 'WagaProduktu')

    # Koszt transportu
    koszt = load_data(file_name, 'Koszt')

    # Koszt dotarcia z J magazynu do M sklepu
    c = {}
    for i in I:
        for j in J:
            for k in produkt[j]:
                c[i, j, k] = koszt[i, j] * waga[
                    k]  # Koszt*waga transportu z magazynu j do klienta i produktu k

    # Model
    model = mctransp(I, J, K, c, d, M)

    # Optymalizacja
    model.optimize()

    EPS = 1.e-6
    x = model.data
    resultAsList = []
    print("Ogolny koszt transportu wynosi:", model.getObjVal())
    for i, j, k in x:
        if model.getVal(x[i, j, k]) > EPS:
            print("Wysylka %10g sztuk %3s z magazynu %3s do klienta %3s" %
                  (model.getVal(x[i, j, k]), k, j, i))
            resultAsList.append([i, j, k, model.getVal(x[i, j, k])])

    return model.getObjVal(), resultAsList
示例#26
0
def example(n):
    """
    Data generator for the one machine scheduling problem.
    """
    J,p,r,d,w = multidict({
        1:[1,4,0,3],
        2:[4,0,0,1],
        3:[2,2,0,2],
        4:[3,4,0,3],
        5:[1,1,0,1],
        6:[4,5,0,2],
        })
    return J,p,r,d,w
示例#27
0
def example(n):
    """
    Data generator for the one machine scheduling problem.
    """
    J,p,r,d,w = multidict({
        1:[1,4,0,3],
        2:[4,0,0,1],
        3:[2,2,0,2],
        4:[3,4,0,3],
        5:[1,1,0,1],
        6:[4,5,0,2],
        })
    return J,p,r,d,w
示例#28
0
def make_data():
    I, d = multidict({1:170,
                     2:270,
                     3:250,
                     4:190,
                     5:200,
                     6:230,
                     7:350,
                     8:450,
                     9:200,
                     10:180,
                     11:190
                     }
                    )  # demand
    J, M, f = multidict({1:[450, 1500],
                       2:[500, 800],
                       3:[500, 1200],
                       4:[600, 1900],
                       5:[400, 1000],
                       6:[550, 1900],
                       7:[350, 1800],
                       8:[800, 4000]
                       }
                    )  # capacity, fixed costs
    c = {(1, 1):5, (1, 2):6, (1, 3):9, (1, 4):4, (1, 5):6, (1, 6):4, (1, 7):9, (1, 8):5,  # transportation costs
         (2, 1):5, (2, 2):4, (2, 3):7, (2, 4):3, (2, 5):5, (2, 6):4, (2, 7):5, (2, 8):5,
         (3, 1):6, (3, 2):3, (3, 3):4, (3, 4):3, (3, 5):2, (3, 6):9, (3, 7):6, (3, 8):4,
         (4, 1):8, (4, 2):5, (4, 3):3, (4, 4):4, (4, 5):7, (4, 6):8, (4, 7):8, (4, 8):6,
         (5, 1):10, (5, 2):8, (5, 3):4, (5, 4):5, (5, 5):6, (5, 6):3, (5, 7):6, (5, 8):7,
         (6, 1):11, (6, 2):6, (6, 3):2, (6, 4):3, (6, 5):4, (6, 6):5, (6, 7):9, (6, 8):8,
         (7, 1):11, (7, 2):6, (7, 3):2, (7, 4):3, (7, 5):5, (7, 6):5, (7, 7):2, (7, 8):4,
         (8, 1):11, (8, 2):6, (8, 3):2, (8, 4):5, (8, 5):5, (8, 6):8, (8, 7):3, (8, 8):6,
         (9, 1):4, (9, 2):6, (9, 3):8, (9, 4):9, (9, 5):7, (9, 6):5, (9, 7):8, (9, 8):5,
         (10, 1):3, (10, 2):5, (10, 3):8, (10, 4):7, (10, 5):5, (10, 6):6, (10, 7):7, (10, 8):7,
         (11, 1):6, (11, 2):9, (11, 3):8, (11, 4):3, (11, 5):2, (11, 6):6, (11, 7):6, (11, 8):8
         }
    return I, J, d, M, f, c
示例#29
0
def example():
    I, d = multidict({1: 80, 2: 270, 3: 250, 4: 160, 5: 180})  # demand
    J, M, f = multidict({
        10: [500, 100],
        11: [500, 100],
        12: [500, 100]
    })  # capacity, fixed costs
    c = {
        (1, 10): 4,
        (1, 11): 6,
        (1, 12): 9,  # transportation costs
        (2, 10): 5,
        (2, 11): 4,
        (2, 12): 7,
        (3, 10): 6,
        (3, 11): 3,
        (3, 12): 4,
        (4, 10): 8,
        (4, 11): 5,
        (4, 12): 3,
        (5, 10): 10,
        (5, 11): 8,
        (5, 12): 4,
    }
    x_pos = {
        1: 0,
        2: 0,
        3: 0,
        4: 0,
        5: 0,
        10: 2,
        11: 2,
        12: 2
    }  # positions of the points in the plane
    y_pos = {1: 2, 2: 1, 3: 0, 4: -1, 5: -2, 10: 1, 11: 0, 12: -1}
    return I, J, d, M, f, c, x_pos, y_pos
示例#30
0
def eld40():
    U,      a,          b,      c,      e,      f,      p_min,  p_max = multidict({
    1  : [ 94.705,  6.73,  0.00690, 100,    0.084,      36,       114],
    2  : [ 94.705,  6.73,  0.00690, 100,    0.084,      36,       114],
    3  : [ 309.54,  7.07,  0.02028, 100,    0.084,      60,       120],
    4  : [ 369.03,  8.18,  0.00942, 150,    0.063,      80,       190],
    5  : [ 148.89,  5.35,  0.01140, 120,    0.077,      47,       97],
    6  : [ 222.33,  8.05,  0.01142, 100,    0.084,      68,       140],
    7  : [ 287.71,  8.03,  0.00357, 200,    0.042,      110,      300],
    8  : [ 391.98,  6.99,  0.00492, 200,    0.042,      135,      300],
    9  : [ 455.76,  6.60,  0.00573, 200,    0.042,      135,      300],
    10 : [ 722.82,  12.9,  0.00605, 200,    0.042,      130,      300],
    11 : [ 635.20,  12.9,  0.00515, 200,    0.042,      94,       375],
    12 : [ 654.69,  12.8,  0.00569, 200,    0.042,      94,       375],
    13 : [ 913.40,  12.5,  0.00421, 300,    0.035,      125,      500],
    14 : [ 1760.4,  8.84,  0.00752, 300,    0.035,      125,      500],
    15 : [ 1728.3,  9.15,  0.00708, 300,    0.035,      125,      500],
    16 : [ 1728.3,  9.15,  0.00708, 300,    0.035,      125,      500],
    17 : [ 647.85,  7.97,  0.00313, 300,    0.035,      220,      500],
    18 : [ 649.69,  7.95,  0.00313, 300,    0.035,      220,      500],
    19 : [ 647.83,  7.97,  0.00313, 300,    0.035,      242,      550],
    20 : [ 647.81,  7.97,  0.00313, 300,    0.035,      242,      550],
    21 : [ 785.96,  6.63,  0.00298, 300,    0.035,      254,      550],
    22 : [ 785.96,  6.63,  0.00298, 300,    0.035,      254,      550],
    23 : [ 794.53,  6.66,  0.00284, 300,    0.035,      254,      550],
    24 : [ 794.53,  6.66,  0.00284, 300,    0.035,      254,      550],
    25 : [ 801.32,  7.10,  0.00277, 300,    0.035,      254,      550],
    26 : [ 801.32,  7.10,  0.00277, 300,    0.035,      254,      550],
    27 : [ 1055.1,  3.33,  0.52124, 120,    0.077,      10,       150],
    28 : [ 1055.1,  3.33,  0.52124, 120,    0.077,      10,       150],
    29 : [ 1055.1,  3.33,  0.52124, 120,    0.077,      10,       150],
    30 : [ 148.89,  5.35,  0.01140, 120,    0.077,      47,       97],
    31 : [ 222.92,  6.43,  0.00160, 150,    0.063,      60,       190],
    32 : [ 222.92,  6.43,  0.00160, 150,    0.063,      60,       190],
    33 : [ 222.92,  6.43,  0.00160, 150,    0.063,      60,       190],
    34 : [ 107.87,  8.95,  0.00010, 200,    0.042,      90,       200],
    35 : [ 116.58,  8.62,  0.00010, 200,    0.042,      90,       200],
    36 : [ 116.58,  8.62,  0.00010, 200,    0.042,      90,       200],
    37 : [ 307.45,  5.88,  0.01610, 80,     0.098,      25,       110],
    38 : [ 307.45,  5.88,  0.01610, 80,     0.098,      25,       110],
    39 : [ 307.45,  5.88,  0.01610, 80,     0.098,      25,       110],
    40 : [ 647.83,  7.97,  0.00313, 300,    0.035,      242,      550],
    })

    U = list(a.keys())
    return U,a,b,c,e,f,p_min,p_max,d
示例#31
0
def eld13():
    U,      a,          b,      c,      e,      f,      p_min,  p_max = multidict({
    1   : [ 550,    8.1,    0.00028,    300,    0.035,  0,      680 ],
    2   : [ 309,    8.1,    0.00056,    200,    0.042,  0,      360 ],
    3   : [ 307,    8.1,    0.00056,    200,    0.042,  0,      360 ],
    4   : [ 240,    7.74,   0.00324,    150,    0.063,  60,     180 ],
    5   : [ 240,    7.74,   0.00324,    150,    0.063,  60,     180 ],
    6   : [ 240,    7.74,   0.00324,    150,    0.063,  60,     180 ],
    7   : [ 240,    7.74,   0.00324,    150,    0.063,  60,     180 ],
    8   : [ 240,    7.74,   0.00324,    150,    0.063,  60,     180 ],
    9   : [ 240,    7.74,   0.00324,    150,    0.063,  60,     180 ],
    10  : [ 126,    8.6,    0.00284,    100,    0.084,  40,     120 ],
    11  : [ 126,    8.6,    0.00284,    100,    0.084,  40,     120 ],
    12  : [ 126,    8.6,    0.00284,    100,    0.084,  55,     120 ],
    13  : [ 126,    8.6,    0.00284,    100,    0.084,  55,     120 ],
    })
    return U, a, b, c, e, f, p_min, p_max
示例#32
0
def make_data():
    I = 10
    d = [instance['customer_%d'%i]['demand']for i in range(1,I+1)] # demand         
    J,M,f = multidict({0:[8,20], 1:[20,20], 2:[20,20]}) # capacity, fixed costs
    xDep = [instance['deport%d' %i]['coordinates']['x'] for i in range(len(J))]
    yDep = [instance['deport%d' %i]['coordinates']['y'] for i in range(len(J))]
    xCust = [instance['customer_%d' %i]['coordinates']['x'] for i in range(1,I+1)]    # positions of the points in the plane
    yCust = [instance['customer_%d' %i]['coordinates']['y'] for i in range(1,I+1)]
    x1 = xDep + xCust
    y1 = yDep + yCust
    c = {}
    for i in range(len(x1)):
        #i = 0
        for j in range(len(y1)):
            #j = 1
            c[i,j] = distance(x1[i],y1[i],x1[j],y1[j])
    return I,J,d,M,f,c
示例#33
0
def make_data():
    # amount of customers
    I = 10

    # get the demand of each customer
    d = [instance['customer_%d' % i]['demand'] for i in range(1, I + 1)]

    # index of station, capacity, fixed costs
    J, M, f = multidict({0: [8, 20], 1: [12, 20], 2: [12, 20]})

    # get the x - coordinates of the depots
    xDep = [instance['deport%d' %i]['coordinates']['x']\
            for i in range(len(J))]

    # get the y - coordinates of the depots
    yDep = [instance['deport%d' %i]['coordinates']['y']\
            for i in range(len(J))]

    # get the x - coordinates of the customers
    xCust = [instance['customer_%d' %i]['coordinates']['x']\
             for i in range(1,I+1)]

    # get the y - coordinates of the customers
    yCust = [instance['customer_%d' %i]['coordinates']['y']\
             for i in range(1,I+1)]

    # concatenate the coordinates of depots and customers
    x1 = xDep + xCust
    y1 = yDep + yCust

    # calculation of the distance between all of them -> matrix
    c = {}
    for i in range(len(x1)):
        #i = 0
        for j in range(len(y1)):
            #j = 1
            c[i, j] = distance(x1[i], y1[i], x1[j], y1[j])
    return I, J, d, M, f, c
示例#34
0
def make_inst2():
    """creates example data set 2"""
    d = {
        (1, 1): 45,  # {(customer,commodity):demand}}
        (2, 1): 20,
        (3, 1): 30,
        (4, 1): 30,
    }
    I = set([i for (i, k) in d])
    K = set([k for (i, k) in d])
    J, M = multidict({1: 35, 2: 50, 3: 40})  # {factory: capacity}}
    produce = {
        1: [1],
        2: [1],
        3: [1]
    }  # products that can be produced in each facility
    weight = {1: 1}  # {commodity: weight}
    cost = {
        (1, 1): 8,
        (1, 2): 9,
        (1, 3): 14,  # {(customer,factory): cost}
        (2, 1): 6,
        (2, 2): 12,
        (2, 3): 9,
        (3, 1): 10,
        (3, 2): 13,
        (3, 3): 16,
        (4, 1): 9,
        (4, 2): 7,
        (4, 3): 5,
    }
    c = {}
    for i in I:
        for j in J:
            for k in produce[j]:
                c[i, j, k] = cost[i, j] * weight[k]

    return I, J, K, c, d, M
示例#35
0
def make_1r():
    """creates example data set 1"""
    J, p = multidict({       # jobs, processing times
        1 : 1,
        2 : 3,
        3 : 2,
        4 : 2,
        })
    P = [(1,2), (1,3), (2,4)]
    R = [1]
    T = 6
    c = {}
    for j in J:
        for t in range(1,T-p[j]+2):
            c[j,t] = 1*(t-1+p[j])
    a = {
        (1,1,0):2,
        (2,1,0):2, (2,1,1):1, (2,1,2):1,
        (3,1,0):1, (3,1,1):1,
        (4,1,0):1, (4,1,1):2,
        }
    RUB = {(1,1):2, (1,2):2, (1,3):1, (1,4):2, (1,5):2, (1,6):2}
    return (J,P,R,T,p,c,a,RUB)
示例#36
0
def make_inst2():
    d = {(1,1):45,                             # {(customer,commodity):demand}}
         (2,1):20,
         (3,1):30,
         (4,1):30,
         }
    I = set([i for (i,k) in d])
    K = set([k for (i,k) in d])
    J,M = multidict({1:35, 2:50, 3:40})       # {factory: capacity}}
    produce = {1:[1], 2:[1], 3:[1]}           # products that can be produced in each facility
    weight = {1:1}                            # {commodity: weight}
    cost = {(1,1):8,    (1,2):9,    (1,3):14, # {(customer,factory): cost}
            (2,1):6,    (2,2):12,   (2,3):9 ,
            (3,1):10,   (3,2):13,   (3,3):16,
            (4,1):9,    (4,2):7,    (4,3):5 ,
            }
    c = {}
    for i in I:
        for j in J:
            for k in produce[j]:
                c[i,j,k] = cost[i,j] * weight[k]

    return I,J,K,c,d,M
示例#37
0
minimize the total transportation cost for satisfying demand at
customers, from capacitated facilities.

Data:
    I - set of customers
    J - set of facilities
    c[i,j] - unit transportation cost on arc (i,j)
    d[i] - demand at node i
    M[j] - capacity

Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2012
"""

from pyscipopt import Model, quicksum, multidict

I, d = multidict({1: 80, 2: 270, 3: 250, 4: 160, 5: 180})  # demand
J, M = multidict({1: 500, 2: 500, 3: 500})  # capacity
c = {
    (1, 1): 4,
    (1, 2): 6,
    (1, 3): 9,  # cost
    (2, 1): 5,
    (2, 2): 4,
    (2, 3): 7,
    (3, 1): 6,
    (3, 2): 3,
    (3, 3): 3,
    (4, 1): 8,
    (4, 2): 5,
    (4, 3): 3,
    (5, 1): 10,
def make_data_10():
    """
    1..T: set of periods
    K: set of resources
    P: set of items
    f[t,p]: set-up costs
    g[t,p]: set-up times
    c[t,p]: variable costs
    d[t,p]: demand values
    h[t,p]: holding costs
    a[t,k,p]: amount of resource k for producing product p in period. t
    M[t,k]: resource upper bounds
    UB[t,p]: upper bound of production time of product p in period t
    phi[(i,j)] : units of i required to produce a unit of j (j parent of i)
    """
    T = 5
    K = [1]
    P = [1,2,3,4,5,6,7,8,9,10]
    _, f, g, c, d, h, UB = multidict({
        (1,1): [10, 1, 2,  0, 0.5, 24],
        (1,2): [10, 1, 2,  0, 0.5, 24],
        (1,3): [10, 1, 2,  0, 0.5, 24],
        (1,4): [10, 1, 2,  0, 0.5, 24],
        (1,5): [10, 1, 2,  0, 0.5, 24],
        (1,6): [10, 1, 2,  0, 0.5, 24],
        (1,7): [10, 1, 2,  0, 0.5, 24],
        (1,8): [10, 1, 2,  0, 0.5, 24],
        (1,9): [10, 1, 2,  0, 0.5, 24],
        (1,10):[10, 1, 2,  0, 0.5, 24],
        (2,1): [10, 1, 2,  0, 0.5, 24],
        (2,2): [10, 1, 2,  0, 0.5, 24],
        (2,3): [10, 1, 2,  0, 0.5, 24],
        (2,4): [10, 1, 2,  0, 0.5, 24],
        (2,5): [10, 1, 2,  0, 0.5, 24],
        (2,6): [10, 1, 2,  0, 0.5, 24],
        (2,7): [10, 1, 2,  0, 0.5, 24],
        (2,8): [10, 1, 2,  0, 0.5, 24],
        (2,9): [10, 1, 2,  0, 0.5, 24],
        (2,10):[10, 1, 2,  0, 0.5, 24],
        (3,1): [10, 1, 2,  0, 0.5, 24],
        (3,2): [10, 1, 2,  0, 0.5, 24],
        (3,3): [10, 1, 2,  0, 0.5, 24],
        (3,4): [10, 1, 2,  0, 0.5, 24],
        (3,5): [10, 1, 2,  0, 0.5, 24],
        (3,6): [10, 1, 2,  0, 0.5, 24],
        (3,7): [10, 1, 2,  0, 0.5, 24],
        (3,8): [10, 1, 2,  0, 0.5, 24],
        (3,9): [10, 1, 2,  0, 0.5, 24],
        (3,10):[10, 1, 2,  0, 0.5, 24],
        (4,1): [10, 1, 2,  0, 0.5, 24],
        (4,2): [10, 1, 2,  0, 0.5, 24],
        (4,3): [10, 1, 2,  0, 0.5, 24],
        (4,4): [10, 1, 2,  0, 0.5, 24],
        (4,5): [10, 1, 2,  0, 0.5, 24],
        (4,6): [10, 1, 2,  0, 0.5, 24],
        (4,7): [10, 1, 2,  0, 0.5, 24],
        (4,8): [10, 1, 2,  0, 0.5, 24],
        (4,9): [10, 1, 2,  0, 0.5, 24],
        (4,10):[10, 1, 2,  0, 0.5, 24],
        (5,1): [10, 1, 2,  0, 0.5, 24],
        (5,2): [10, 1, 2,  0, 0.5, 24],
        (5,3): [10, 1, 2,  0, 0.5, 24],
        (5,4): [10, 1, 2,  0, 0.5, 24],
        (5,5): [10, 1, 2,  0, 0.5, 24],
        (5,6): [10, 1, 2,  0, 0.5, 24],
        (5,7): [10, 1, 2,  0, 0.5, 24],
        (5,8): [10, 1, 2,  0, 0.5, 24],
        (5,9): [10, 1, 2,  0, 0.5, 24],
        (5,10):[10, 1, 2,  5, 0.5, 24],
        })
    a = {
        (1,1,1): 1, (1,1,2): 1, (1,1,3): 1, (1,1,4): 1, (1,1,5): 1, (1,1,6): 1, (1,1,7): 1, (1,1,8): 1, (1,1,9): 1, (1,1,10): 1,
        (2,1,1): 1, (2,1,2): 1, (2,1,3): 1, (2,1,4): 1, (2,1,5): 1, (2,1,6): 1, (2,1,7): 1, (2,1,8): 1, (2,1,9): 1, (2,1,10): 1,
        (3,1,1): 1, (3,1,2): 1, (3,1,3): 1, (3,1,4): 1, (3,1,5): 1, (3,1,6): 1, (3,1,7): 1, (3,1,8): 1, (3,1,9): 1, (3,1,10): 1,
        (4,1,1): 1, (4,1,2): 1, (4,1,3): 1, (4,1,4): 1, (4,1,5): 1, (4,1,6): 1, (4,1,7): 1, (4,1,8): 1, (4,1,9): 1, (4,1,10): 1,
        (5,1,1): 1, (5,1,2): 1, (5,1,3): 1, (5,1,4): 1, (5,1,5): 1, (5,1,6): 1, (5,1,7): 1, (5,1,8): 1, (5,1,9): 1, (5,1,10): 1,
        }
    M = {
        (1,1): 25,
        (2,1): 25,
        (3,1): 25,
        (4,1): 25,
        (5,1): 25,
        (6,1): 25,
        (7,1): 25,
        (8,1): 25,
        (9,1): 25,
        (10,1):25,
        }

    phi = {     # phi[(i,j)] : units of i required to produce a unit of j (j parent of i)
        (1,2):1,
        (2,5):2,
        (3,4):3,
        (4,5):1,
        (5,6):1,
        (6,10):1/2.,
        (3,7):1,
        (7,8):3/2.,
        (8,9):3,
        (9,10):1
        }


    return T,K,P,f,g,c,d,h,a,M,UB,phi
                 {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.11, "W05": 0.00, "W06": 0.00, "W07": 0.09}]
    })


M = 20
B = 10100
FIXED_COST = 500

Scenarios = [1, 2, 3]

Parcels, Areas = multidict({
    1: 13,
    2: 7,
    3: 13,
    4: 15,
    5: 8,
    6: 14,
    7: 8,
    8: 15,
    9: 14,
    10: 10
})


def assignment02(SCENARIO1Revenue, SCENARIO2Revenue, SCENARIO3Revenue,
                 SCENARIO1Yield, SCENARIO2Yield, SCENARIO3Yield,
                 Varieties, WineBrand, Percentage, Costs, Areas, Parcels, BigM, Scenarios):
    model = Model("assignment02")

    ###################
    # -- Variables -- #
    ###################
示例#40
0
    model.addCons(rhoaux == (alpha - rho)*(1/phi_inv(beta))) #todo
    model.addCons(quicksum(sigma[i]**2 * x[i] * x[i] for i in I) <=  rhoaux * rhoaux)

    model.setObjective(rho, "maximize")

    model.data = x
    return model



if __name__ == "__main__":
    # portfolio
    I,sigma,r = multidict(
        {1:[0.07,1.01],
         2:[0.09,1.05],
         3:[0.1,1.08],
         4:[0.2,1.10],
         5:[0.3,1.20]}
        )
    alpha = 0.95
    # beta = 0.1

    for beta in [0.1, 0.05, 0.02, 0.01]:
        print("\n\n\nbeta:",beta,"phi inv:",phi_inv(beta))
        model = p_portfolio(I,sigma,r,alpha,beta)
        model.optimize()

        x = model.data
        EPS = 1.e-6
        print("Investment:")
        print("%5s\t%8s" % ("i","x[i]"))
示例#41
0
    for i in I:
        model.addCons(F[i] <= c[i]*T[i])

    model.addCons(quicksum(w[i]*d[i]*T[i] for i in I) <= W)

    model.setObjective(quicksum(c[i] + h[i]*d[i]*T[i]*0.5 for i in I), "minimize")

    model.data = T,c
    return model



if __name__ == "__main__":
    # multiple item EOQ
    I,F,h,d,w = multidict(
        {1:[300,10,10,20],
         2:[300,10,30,40],
         3:[300,10,50,10]}
        )
    W = 2000
    model = eoq_soco(I,F,h,d,w,W)
    model.optimize()

    T,c = model.data
    EPS = 1.e-6
    print("%5s\t%8s\t%8s" % ("i","T[i]","c[i]"))
    for i in I:
        print("%5s\t%8g\t%8g" % (i,model.getVal(T[i]),model.getVal(c[i])))
    print
    print("Optimal value:", model.getObjVal())
示例#42
0
        model.addCons(quicksum(a[i, k] * w_[i, k] for k in range(K)) == x[i])
        model.addCons(quicksum(b[i, k] * w_[i, k] for k in range(K)) == c[i])

    model.addCons(quicksum(w[i] * d[i] * x[i] for i in I) <= W)

    model.setObjective(quicksum(c[i] for i in I), "minimize")

    model.data = x, w
    return model


if __name__ == "__main__":
    # multiple item EOQ
    I, F, h, d, w = multidict({
        1: [300, 10, 10, 20],
        2: [300, 10, 30, 40],
        3: [300, 10, 50, 10]
    })
    W = 2000
    K = 1000
    a0, aK = 0.1, 10
    model = eoq(I, F, h, d, w, W, a0, aK, K)
    model.optimize()

    x, w = model.data
    EPS = 1.e-6
    for v in x:
        if model.getVal(x[v]) >= EPS:
            print(x[v].name, "=", model.getVal(x[v]))

    print("Optimal value:", model.getObjVal())
示例#43
0
from pyscipopt import Model, quicksum, multidict
I, d = multidict({1: 80, 2: 270, 3: 250, 4: 160, 5: 180})
J, M = multidict({1: 500, 2: 500, 3: 500})
c = {
    (1, 1): 4,
    (1, 2): 6,
    (1, 3): 9,
    (2, 1): 5,
    (2, 2): 4,
    (2, 3): 7,
    (3, 1): 6,
    (3, 2): 3,
    (3, 3): 3,
    (4, 1): 8,
    (4, 2): 5,
    (4, 3): 3,
    (5, 1): 10,
    (5, 2): 8,
    (5, 3): 4,
}
model = Model("transportation")
x = {}
for i in I:
    for j in J:
        x[i, j] = model.addVar(vtype="C", name="x(%s,%s)" % (i, j))
for i in I:
    model.addCons(quicksum(x[i, j] for j in J if (i, j) in x) == d[i],
                  name="Demand(%s)" % i)
for j in J:
    model.addCons(quicksum(x[i, j] for i in I if (i, j) in x) <= M[j],
                  name="Capacity(%s)" % j)
class SCENARIO1:
    WineBrands, Revenues = multidict({
        "W01": 12.39,
        "W02": 11.94,
        "W03": 12.15,
        "W04": 13.71,
        "W05": 10.88,
        "W06": 12.99,
        "W07": 11.92
    })

    Varieties, Costs, Yields, Percentages = multidict({
        "Alfrocheiro": [11, {1: 1.20, 2: 1.07, 3: 0.75, 4: 1.20, 5: 0.81, 6: 0.72, 7: 0.51, 8: 1.25, 9: 1.22, 10: 1.40},
                        {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.21, "W07": 0.00}],
        "Amaral": [60, {1: 1.34, 2: 1.45, 3: 1.49, 4: 0.94, 5: 0.67, 6: 1.11, 7: 0.91, 8: 1.15, 9: 0.79, 10: 0.53},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Aragonez": [42, {1: 1.01, 2: 0.90, 3: 0.52, 4: 1.32, 5: 1.15, 6: 0.58, 7: 0.80, 8: 1.15, 9: 0.76, 10: 1.40},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Aramon": [67, {1: 1.24, 2: 1.21, 3: 0.96, 4: 1.31, 5: 1.49, 6: 1.21, 7: 0.77, 8: 1.46, 9: 1.47, 10: 1.50},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.15}],
        "Baga": [36, {1: 1.02, 2: 1.44, 3: 1.11, 4: 1.22, 5: 0.92, 6: 0.78, 7: 1.42, 8: 1.12, 9: 0.55, 10: 0.63},
                 {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Bastardo": [42, {1: 0.82, 2: 1.22, 3: 0.53, 4: 1.18, 5: 0.59, 6: 1.16, 7: 0.62, 8: 0.57, 9: 1.15, 10: 0.90},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Bonvedro": [52, {1: 0.64, 2: 1.30, 3: 0.71, 4: 1.11, 5: 1.05, 6: 1.42, 7: 0.85, 8: 1.03, 9: 1.09, 10: 0.55},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.20, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Branjo": [37, {1: 1.26, 2: 1.45, 3: 1.13, 4: 1.09, 5: 0.60, 6: 0.58, 7: 1.08, 8: 0.51, 9: 0.80, 10: 1.06},
                   {"W01": 0.00, "W02": 0.42, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Cabinda": [62, {1: 0.75, 2: 0.83, 3: 1.15, 4: 0.73, 5: 1.33, 6: 0.69, 7: 1.10, 8: 1.15, 9: 0.84, 10: 1.30},
                    {"W01": 0.00, "W02": 0.00, "W03": 0.10, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Casculho": [48, {1: 0.70, 2: 1.22, 3: 1.24, 4: 0.85, 5: 0.91, 6: 1.40, 7: 1.26, 8: 1.34, 9: 0.74, 10: 0.53},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Cidadelhe": [14, {1: 1.14, 2: 0.97, 3: 1.48, 4: 0.87, 5: 1.47, 6: 1.19, 7: 1.17, 8: 1.48, 9: 1.34, 10: 0.57},
                      {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.31, "W07": 0.00}],
        "Cidreiro": [21, {1: 0.64, 2: 0.73, 3: 0.98, 4: 1.44, 5: 1.39, 6: 0.56, 7: 0.79, 8: 1.46, 9: 1.44, 10: 1.26},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Concieira": [22, {1: 0.84, 2: 1.39, 3: 1.36, 4: 1.02, 5: 1.21, 6: 1.10, 7: 1.40, 8: 1.06, 9: 0.83, 10: 1.48},
                      {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Cornifesto": [66, {1: 1.48, 2: 0.90, 3: 1.09, 4: 1.01, 5: 1.43, 6: 0.98, 7: 0.55, 8: 1.40, 9: 0.64, 10: 0.81},
                       {"W01": 0.09, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Corropio": [24, {1: 0.94, 2: 0.84, 3: 1.21, 4: 0.53, 5: 0.59, 6: 1.48, 7: 0.76, 8: 1.25, 9: 0.70, 10: 1.06},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.10, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Corvo": [41, {1: 0.79, 2: 0.80, 3: 0.53, 4: 1.43, 5: 1.30, 6: 0.98, 7: 0.86, 8: 1.03, 9: 0.71, 10: 0.68},
                  {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Deliciosa": [85, {1: 0.94, 2: 0.86, 3: 1.33, 4: 1.40, 5: 0.65, 6: 0.59, 7: 1.08, 8: 0.74, 9: 1.21, 10: 1.13},
                      {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.08, "W06": 0.00, "W07": 0.00}],
        "Donzelinho": [89, {1: 1.01, 2: 1.00, 3: 0.75, 4: 1.14, 5: 1.25, 6: 0.91, 7: 1.42, 8: 0.99, 9: 1.33, 10: 0.56},
                       {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.08, "W06": 0.00, "W07": 0.00}],
        "Engomada": [74, {1: 1.42, 2: 0.51, 3: 1.07, 4: 0.92, 5: 0.93, 6: 0.87, 7: 1.25, 8: 0.94, 9: 0.60, 10: 1.25},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Espadeiro": [68, {1: 1.39, 2: 0.58, 3: 1.01, 4: 0.96, 5: 0.51, 6: 1.11, 7: 0.81, 8: 1.44, 9: 0.61, 10: 1.41},
                      {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Ferral": [60, {1: 0.76, 2: 1.03, 3: 1.39, 4: 0.68, 5: 1.18, 6: 1.26, 7: 1.13, 8: 0.55, 9: 1.13, 10: 1.11},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.22, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Galego": [33, {1: 0.54, 2: 0.82, 3: 0.55, 4: 1.39, 5: 1.11, 6: 1.29, 7: 0.75, 8: 1.35, 9: 0.63, 10: 1.41},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.13}],
        "Grangeal": [35, {1: 1.09, 2: 1.35, 3: 0.59, 4: 1.10, 5: 1.32, 6: 1.09, 7: 0.56, 8: 1.39, 9: 0.53, 10: 1.28},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.15, "W06": 0.00, "W07": 0.02}],
        "Lourela": [22, {1: 1.35, 2: 1.32, 3: 0.57, 4: 1.00, 5: 0.51, 6: 1.31, 7: 0.68, 8: 1.00, 9: 0.77, 10: 0.61},
                    {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.21, "W07": 0.00}],
        "Lusitano": [67, {1: 0.76, 2: 0.55, 3: 1.12, 4: 1.25, 5: 1.25, 6: 0.94, 7: 1.26, 8: 1.11, 9: 0.96, 10: 0.94},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Malandra": [84, {1: 1.09, 2: 1.49, 3: 0.98, 4: 1.16, 5: 0.74, 6: 0.95, 7: 1.32, 8: 0.72, 9: 0.57, 10: 1.24},
                     {"W01": 0.00, "W02": 0.05, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Malvarisco": [15, {1: 1.32, 2: 1.37, 3: 0.80, 4: 1.07, 5: 0.72, 6: 0.58, 7: 1.46, 8: 1.17, 9: 0.60, 10: 0.83},
                       {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Marufo": [96, {1: 0.74, 2: 1.33, 3: 1.32, 4: 1.20, 5: 1.43, 6: 1.48, 7: 0.97, 8: 0.56, 9: 0.69, 10: 1.43},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Melra": [60, {1: 0.81, 2: 0.89, 3: 0.63, 4: 1.33, 5: 1.35, 6: 1.01, 7: 0.51, 8: 0.99, 9: 1.15, 10: 1.01},
                  {"W01": 0.00, "W02": 0.00, "W03": 0.29, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.16}],
        "Molar": [95, {1: 1.27, 2: 0.75, 3: 1.47, 4: 1.13, 5: 0.79, 6: 0.98, 7: 1.37, 8: 1.09, 9: 1.30, 10: 0.78},
                  {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Monvedro": [72, {1: 1.10, 2: 1.16, 3: 0.68, 4: 0.65, 5: 0.88, 6: 1.11, 7: 0.76, 8: 0.61, 9: 0.85, 10: 0.56},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Moreto": [44, {1: 1.42, 2: 1.31, 3: 1.13, 4: 1.25, 5: 1.20, 6: 0.88, 7: 1.05, 8: 0.79, 9: 1.14, 10: 0.69},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Moscatel": [11, {1: 1.47, 2: 1.40, 3: 1.22, 4: 1.38, 5: 1.17, 6: 0.97, 7: 0.80, 8: 0.57, 9: 0.66, 10: 0.67},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.08}],
        "Mourisco": [24, {1: 1.49, 2: 0.89, 3: 0.78, 4: 1.02, 5: 1.07, 6: 0.60, 7: 1.08, 8: 1.18, 9: 0.76, 10: 0.98},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Mulata": [24, {1: 1.15, 2: 1.32, 3: 1.22, 4: 0.65, 5: 0.55, 6: 0.70, 7: 0.72, 8: 0.91, 9: 0.79, 10: 0.85},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Nevoeira": [67, {1: 1.12, 2: 1.25, 3: 1.02, 4: 0.70, 5: 0.76, 6: 0.80, 7: 0.73, 8: 1.17, 9: 0.66, 10: 0.62},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.22, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Padeiro": [94, {1: 1.43, 2: 0.93, 3: 1.12, 4: 1.23, 5: 0.94, 6: 0.71, 7: 1.03, 8: 0.70, 9: 0.77, 10: 1.22},
                    {"W01": 0.14, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.47, "W06": 0.00, "W07": 0.00}],
        "Patorra": [21, {1: 1.17, 2: 0.83, 3: 0.71, 4: 1.32, 5: 0.91, 6: 0.95, 7: 1.03, 8: 0.52, 9: 1.22, 10: 1.04},
                    {"W01": 0.14, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.08}],
        "Pedral": [79, {1: 0.87, 2: 1.21, 3: 1.37, 4: 1.03, 5: 1.48, 6: 1.07, 7: 0.52, 8: 1.12, 9: 0.92, 10: 0.68},
                   {"W01": 0.00, "W02": 0.06, "W03": 0.00, "W04": 0.17, "W05": 0.00, "W06": 0.00, "W07": 0.06}],
        "Pilongo": [41, {1: 1.02, 2: 1.49, 3: 0.57, 4: 0.73, 5: 1.02, 6: 1.08, 7: 0.55, 8: 1.33, 9: 1.34, 10: 1.36},
                    {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Ramisco": [31, {1: 0.77, 2: 0.72, 3: 1.01, 4: 1.12, 5: 0.94, 6: 0.61, 7: 0.51, 8: 0.54, 9: 0.88, 10: 0.54},
                    {"W01": 0.28, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Ricoca": [86, {1: 0.59, 2: 0.79, 3: 0.68, 4: 1.37, 5: 1.35, 6: 1.50, 7: 1.42, 8: 1.02, 9: 0.71, 10: 0.87},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.05, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Rufete": [21, {1: 0.74, 2: 1.37, 3: 0.60, 4: 1.04, 5: 1.38, 6: 0.79, 7: 1.48, 8: 1.21, 9: 1.20, 10: 1.21},
                   {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.11}],
        "Saborinho": [29, {1: 1.01, 2: 1.38, 3: 1.37, 4: 1.48, 5: 1.35, 6: 1.38, 7: 0.61, 8: 0.63, 9: 1.42, 10: 0.52},
                      {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Tintinha": [12, {1: 1.45, 2: 1.48, 3: 1.45, 4: 1.46, 5: 1.10, 6: 0.95, 7: 1.38, 8: 1.30, 9: 1.27, 10: 1.07},
                     {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Touriga": [50, {1: 1.02, 2: 0.84, 3: 0.90, 4: 1.47, 5: 1.25, 6: 0.86, 7: 0.80, 8: 1.23, 9: 0.86, 10: 0.82},
                    {"W01": 0.23, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Trincadeira": [46, {1: 1.37, 2: 1.18, 3: 0.81, 4: 0.99, 5: 1.06, 6: 0.68, 7: 0.89, 8: 0.73, 9: 0.64, 10: 0.52},
                        {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Triunfo": [77, {1: 0.95, 2: 1.23, 3: 1.46, 4: 1.39, 5: 0.83, 6: 1.15, 7: 0.65, 8: 0.53, 9: 0.87, 10: 0.90},
                    {"W01": 0.00, "W02": 0.09, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Varejoa": [93, {1: 1.19, 2: 0.69, 3: 0.67, 4: 1.32, 5: 0.53, 6: 1.16, 7: 0.96, 8: 0.65, 9: 0.58, 10: 1.25},
                    {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.00, "W05": 0.00, "W06": 0.00, "W07": 0.00}],
        "Xara": [10, {1: 0.55, 2: 1.40, 3: 1.00, 4: 1.04, 5: 1.29, 6: 0.70, 7: 1.29, 8: 1.13, 9: 0.94, 10: 1.38},
                 {"W01": 0.00, "W02": 0.00, "W03": 0.00, "W04": 0.11, "W05": 0.00, "W06": 0.00, "W07": 0.09}]
    })
def mkp(I, J, v, a, b):
    model = Model("mkp")
    x = {}
    for j in J:
        x[j] = model.addVar(vtype="B", name="x[%d]" % j)
    # model.update()
    for i in I:
        model.addCons(
            quicksum(a[i, j] * x[j] for j in J) <= b[i], "Dimension[%d]" % i)
    model.setObjective(quicksum(v[j] * x[j] for j in J))
    # model.update()
    return model


J, v = multidict({1: 16, 2: 19, 3: 23, 4: 28})
a = {
    (1, 1): 2,
    (1, 2): 3,
    (1, 3): 4,
    (1, 4): 5,
    (2, 1): 3000,
    (2, 2): 3500,
    (2, 3): 5100,
    (2, 4): 7200,
}
I, b = multidict({1: 7, 2: 10000})

model = mkp(I, J, v, a, b)
# model.ModelSense = -1
model.optimize()