GEKKO - Mixed Integer Programming

Viewed 117

I am trying to solve a Mixed Integer problem using GEKKO.

p : continuous variable
I : binary indicator

I can find a solution for this case as an example:

mdl.Equation(p[0][0][0] == 4)

but, I am looking for a kind of solution as follows based on the binary indicator:

mdl.Equation(p[0][0][0]* I[0][0][0] == 4)
def testGEKKO():
        import numpy as np
        from gekko import GEKKO

        t = np.linspace(1,6,6)
        m = np.linspace(1,3,3)
        j = np.linspace(1,2,2)
        
        c = np.array([0.0485, 0.0593, 0.0692, 0.0790, 0.085, 0.0883])
        
        mdl = GEKKO()
        
        p = mdl.Array(mdl.Var, (len(t), len(m), len(j)), lb = 0, ub = 5, integer = False)
        I = mdl.Array(mdl.Var, (len(t), len(m), len(j)), lb = 0, ub = 1, integer = True)
        
        mdl.options.SOLVER = 1
        for tt in range(len(t)):
            for mm in range(len(m)):
                for jj in range(len(j)):
                    mdl.Minimize(c[tt] * p[tt][mm][jj] * I[tt][mm][jj])
                    
        mdl.Equation(p[0][0][0]* I[0][0][0] == 4)
        mdl.options.SOLVER = 1            
        mdl.solve(disp=True)
        
        return p, I
1 Answers

Try writing the equation differently so that p[0][0][0]=4 when the binary indicator is one.

mdl.Equation((p[0][0][0]-4)* I[0][0][0] == 0)

With the original expression, 0==4 is an infeasible if the binary indicator is zero.

mdl.Equation(p[0][0][0]* I[0][0][0] == 4)
Related