Skip to main content

Infeasible model

Awaiting user input

Comments

3 comments

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Ensieh,

    Can you extend your code so that it is a reproducible example?  This will make it easier for someone from the community to lend help.

    - Riley

    0
  • ENSIEH GHAEDYHEIDARY
    First Question
    First Comment

    Sure! Please see below.

            n = 20
            m = 20
            p = 1
            betha1 = 0.567 / 1000  
            a = np.full(n, 55)
            scale = 4
            v = np.ceil(np.array([1046., 1046., 627.6, 1046., 627.6, 1046., 1046., 627.6,
                            627.6, 627.6, 1046., 627.6, 627.6, 1046., 627.6, 627.6,
                            1046., 627.6, 1046., 1046.]))
            df = pd.read_excel('distances.xlsx')
            d_ij = df.values
            d_ij = np.tile(d_ij, (scale, 1))
            d_jk_l = [40, 440, 20, 0, 60, 170, 50, 30, 80, 340, 50, 390, 90, 90, 110, 70, 300, 50, 1390, 80]
            d_jk = np.array(d_jk_l).reshape(-1, 1)
            D = np.array([626, 241, 178, 151, 151, 78, 87, 62, 60, 48, 53, 39, 32, 35, 40, 20, 27, 30, 28, 37])
            D = np.tile(D, scale)
            D = D.astype('int64')

            c = np.round(np.multiply(betha1, d_jk), 5)  
            t = np.round(np.multiply(betha1, d_ij), 5)  

            Main = Model(name='main') 
            Main.Params.LogToConsole = 0
            Main.Params.MIPGap = 1e-6
            Main.Params.OptimalityTol = 1e-6
            Main.Params.IntFeasTol = 1e-6
            Main.Params.Presolve = 2 
            Main.Params.ImproveStartGap = 1e-6
            Main.Params.NumericFocus = 3 
            
            x = Main.addMVar((m, n), vtype = GRB.BINARY)
            y = Main.addMVar((n, p), vtype = GRB.CONTINUOUS)
            y2 = Main.addMVar((n, p), vtype = GRB.CONTINUOUS)
            z = Main.addMVar((n), vtype = GRB.BINARY)
            D2 = np.power(D, 4)
            Main.setParam("NonConvex", 2)
            
            obj = (quicksum(a[j]*z[j] for j in range (n)) 
                   + quicksum(c[j,k]*(y2[j,k]) for j in range (n) for k in range (p)) 
                   + quicksum(t[i,j]*x[i,j]* (D2[i]) for i in range (m)  for j in range (n)))

            
            Main.setObjective(obj, GRB.MINIMIZE)
            for j in range(n):  
                for k in range(p):  
                    Main.addGenConstrPow(y[j, k], y2[j, k], 4)
                    
            Main.addConstrs(quicksum(x[i, j] for j in range (n)) == 1 for i in range (m))
            Main.addConstrs(quicksum(D[i]*x[i, j] for i in range (m)) == 
                            quicksum(y[j,k] for k in range (p)) for j in range (n))
            Main.addConstrs(y[j,k] >= 0 for j in range (n) for k in range (p))
            Main.addConstrs(y2[j,k] >= 0 for j in range (n) for k in range (p))
            Main.addConstrs(quicksum(y[j,k] for k in range (p)) <= v[j]*z[j] for j in range (n))
            Main.addConstrs(quicksum(D[i]*x[i,j] for i in range (m)) <= v[j]*z[j] for j in range (n))
            Main.optimize() 
            print(Main.objval)

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Ensieh,

    df = pd.read_excel('distances.xlsx')

    Your code is not reproducible.

    - Riley

    0

Please sign in to leave a comment.