I have written a program for optimizing a set of generators. I have hourly price and cost data and need to figure out when a generator should run or just stay off. I describe the problem in more detail below. I have programed this using matlabs global optimization toolbox and the ga solver. I run the solver and each time I run the solver I get a different solution. I am thinking this is because ga is no able to properly search the solution space for an optimal solution? Is it unable to cope with the use of $x_3$ to turn the generator off?

The solver stops with this status:

Optimization terminated: average change in the penalty fitness value less than options.TolFun and constraint violation is less than options.TolCon.

Problem Description

$x_1$ is the generator output at any one point in time and is constrained to be between a min and max capacity

$x_2$ is an integer variable used simply to turn the generator off completely

$x_3$ lastly is another integer variable used to apply a startup cost whenever the generator is switched on.

Objective Function (totrevenue6):

$efficiency6 = 0.2621*x_1 - 0.1229*x_1^2 + 0.2543$

$income6 = \frac{-x_1*(AC_1 + FC_1 - P_1 + FC_1)}{efficiency6}$

$revenue6 = - SC_1*x_3 - x_2*(income6)$

totrevenue6 = -sum(revenue6)


  • min_capacity <= generator6 power ($x_1$) <= max_capacity
  • 0 <= generator6 toggle ($x_2$)<= 1
  • The startup constraint ($x_3$) is $x_j-x_{j-1}<=s_j$ and rearranging $-x_{j-1}+x_j-s_j<=0$
  • 0 <= ($x_3$)<= 1

So my question(s) why does ga solver reach a new solution every time I run it? How do I get the solver to solve this type of problem?

many thanks


ga does not garantee an optimal solution. However you can heuristically tune ga parameters (generation number, initial individuals, crossing factor...) to finish near the value you want. Check the help of ga and opimset for more details.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.