1
$\begingroup$

Python==3.9.5, scipy==1.13.0

My model has some variable coefficients in each round of calculation. for example, for a four-dimensional decision variable x=(x1, x2, x3, x4)

from scipy.optimize import minimize()



groups = [
  [a1,b1,c1,d1],
  [a2,b2,c2,d2],
  [a3,b3,c3,d3]
]
groups2 = [
  [e1, f1],
  [e2, f2]
]
cost_coefficient = [cost1, cost2, cost3, cost4]

def objFunc(x):
   '''
   here is my objective func, a linear equation
   '''
   value_objFunc = a * x[0] * cost1 + b * x[1] * cost2 + c * x[2] * cost3 + d * x[3] * cost4
   return value_objFunc


# here is the constraints of my model
cons = [{'type': 'eq', 'fun': lambda x: (a + b + c + d) * x[0] + (e + f) * x[1] - 1},
        {'type': 'eq', 'fun': lambda x: (a + b + c + d) * x[2] + (e + f) * x[3] - 1},
]


# solve
try_times = 3
for g1 in groups:
  a, b, c, d = g1[0], g1[1], g1[2], g1[3]
  for g2 in groups2:
    e, f = g2[0], g2[1]
    for _ in range(try_times): 
      r1 = random.uniform(0, 1) 
      r2 = random.uniform(0, 1) 
      r3 = random.uniform(0, 1) 
      r4 = random.uniform(0, 1)  
      x0 = np.asarray((r1, r2, r3, r4))  # randomly generated initial solution
    
      res = minimize(objFunc, x0, method='SLSQP', constraints=cons)
        if res.success:
          # some code to record the answer

Notice the number of lists in groups can be up to thousands. And I've made sure that the combination of g1 and g2 will not be repeated

What made me dissatisfied was that I found that there would be infeasible in many cases during the calculation of the model, resulting in redundant calculation and wasting time. I want to find a way to avoid computing models of doomed groups as much as possible.

Is there any way to judge the model without solution before computing the model body?

$\endgroup$
5
  • 1
    $\begingroup$ Show us what is contained in value_objFunc. $\endgroup$
    – Brannon
    Commented May 31 at 18:26
  • $\begingroup$ @Brannon ok I have edited it. By the way, my model has three goals, and my method is to solve each one once, where goal 1 is a linear equation as shown in the case, while the second and third goals are nonlinear; All constraints are linear constraints $\endgroup$
    – CangWangu
    Commented Jun 4 at 2:16
  • 1
    $\begingroup$ Whether a problem is infeasible or not has nothing to do with the objective. $\endgroup$ Commented Jun 4 at 8:11
  • $\begingroup$ You could solve a linear problem first with an LP solver. If feasible, continue with the NLP solver. In addition, you can run things in parallel. $\endgroup$ Commented Jun 4 at 8:32
  • $\begingroup$ @Erwin Kalvelagen sir your comment opened the door for me: If I have a single objective optimization model whose objective function is nonlinear but the constraints are all linear, can I solve this model using a solver that is specifically designed for linear model solving (e.g. scipy.optimize.linprog)? Can this model be counted as linear? $\endgroup$
    – CangWangu
    Commented Jun 5 at 1:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.