Optimization of a simple expansion problem

minimise: $$ \sum_{t=1}^{5}\left[\sum_{i=1}^{2}x_{i,t}CC_i\left(\frac{1+EIC}{1+r}\right)^t+UE_t*C_{UE}\right] $$ subject to: $$ 0 \leq x_{i,t} \leq 5 \\ ED_B(I+\alpha)^t=\sum_{i=1}^{2}\sum_{j=1}^{t}x_{ij}G_{ij}+UE_t\\ ED_B,\alpha\in\Bbb{R}\\ UE=[\;4.5,4.8,4.2,4.0,5.0\;]\;kWH\\ C_{UE}=0.05$ \\ (Escalation\;in\;CC)\;EIC=4\;\% \\ (Annual\;Discount)\;r=5\;\% $$

I want to minimize a cost function accumulating over 5 years with some constraints on energy balance and bounds on the integer variables. It could be a mixed-integer problem.

How to formulate in MatLab or any other tools that I can use to write and solve.

CVX tutorial for such a problem is highly appreciated.


  • 2
    $\begingroup$ Welcome to OR.SE. You could try using many of the commercial or open-source solvers like CPLEX, Gurobi, CVX, etc. You will need to start with one of them and if you have any issue ask your question again. :) $\endgroup$
    – A.Omidi
    May 14, 2020 at 15:56
  • $\begingroup$ It is good practice to make clear what symbols are input data and what the optimization (a.k.a. decision0 variables are, rather than making the reader guess. Which, if any, things other than $x_{i,j}$ are optimization variables? Which, if any, of the optimization variables are constrained to be integer? $\endgroup$ May 15, 2020 at 2:33
  • $\begingroup$ That is not linear or even convex. Right? $\endgroup$ May 15, 2020 at 5:43

1 Answer 1


You can write the model using Hexaly, our global optimization solver. Please note that Hexaly is a commercial software like MATLAB. Nevertheless, you can benefit from a free trial or academic license.

function model() {
  x[i in 1..2][t in 1..5] <- int(0, 5);
  EDB <- float(-1e3, 1e3);
  alpha <- float(-1e3, 1e3);

  for[t in 1..5] {
    constraint EDB * pow(1 + alpha, t) == sum[i in 1..2][j in 1..t](x[i][j] * G[i][j]) + UE[t];

  minimize sum[t in 1..5][i in 1..2](x[i][t] * CC[i] * pow((1 + EIC) / (1 + r), t) + UE[t] * Cue);

To make it work, you have to add the input data like this:

function input() {
  // we skip t = 0
  UE = {0, 4.5, 4.8, 4.2, 4.0, 5.0};
  Cue = 0.05;
  EIC = 0.04;
  r = 0.05;

  // Dummy data for G_ij
  G = {
    {}, //skip index 0
    {0, 0.42, 0.63, 0.18, 0.78, 0.44},
    {0, 0.06, 0.65, 0.92, 0.71, 0.98}

  // Dummy data for CC_i
  CC = {0, 0.5, 0.5};

As shown above, we have tried to complete the missing data with some values. Using this data, the model is unfeasible (no surprise).

  • $\begingroup$ Care to share why the model is unfeasible? @LocalSolver $\endgroup$
    – Dan
    Jun 21, 2022 at 7:18
  • $\begingroup$ Nice to follow up two years after :-) Showing or explaining infeasibility may be challenging in mathematical optimization. This is the case here. We have no proof of infeasibility. But LocalSolver was not able to find a feasible solution in minutes. If you are interested in investigating, you can ask for a LocalSolver free trial license. You are very much welcome. $\endgroup$
    – Hexaly
    Jun 22, 2022 at 21:18
  • $\begingroup$ Thank you @LocalSolver. I will try to investigate analytically $\endgroup$
    – Dan
    Jun 24, 2022 at 15:46

Your Answer

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

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