When we run our C++ Gurobi code, sometimes we end up getting a result saying the problem is “infeasible”. How do we figure out makes the code infeasible?
First thing first, if you are using a reusable code, your code was working for another example before but just not working with this new example, then please check your input data format. Print out your input data using your C++ code and see whether the data were read properly.
Let’s say we have an optimization problem written in the form of the following pseudo-code:
Objective;
Constraint 1;
Constraint 2;
Constraint 3;
Constraint 4;
Constraint 5;
If we solve this problem and get an infeasible result, what we could do is,
1. Figure out which constraints are causing the infeasibility
Let’s make a guess on which constraint might be causing the infeasibility. If you have no idea, then let’s start with the first constraint. Let’s comment out the first constraint, compile and run the code again:
Objective;
// Constraint 1;
Constraint 2;
Constraint 3;
Constraint 4;
Constraint 5;
If we can find a feasible result this time, then it is very likely that Constraint 1 is causing the infeasibility.
If we still cannot find a feasible result, then uncomment this constraint, and comment the next constraint, compile and run the code again:
Objective;
Constraint 1;
// Constraint 2;
Constraint 3;
Constraint 4;
Constraint 5;
We could just repeat this process until we figure out which constraint is causing the infeasibility.
Notes:
1). Sometimes, we have to comment out multiple constraints to get a feasible result.
2). Sometimes, if we comment out one constraint, we can get a feasible result; if we comment out another, it could also give us a feasible result. But if we have the two constraints at the same time, we don’t get a feasible result. In this case, the two constraints are conflicting each other. So even if you have already found the suspicious constraint, you might still want to check other constraints.
2. Figure out why these constraints are causing the infeasibility
Once we figure out which constraints are causing the infeasibility, we need to figure out why they do. This has to be analyzed on a case-by-case basis.
For example, if the power balance constraint is causing the issue, we might want to check whether our system has enough capacity to meet the demand.
If the power flow limit constraint is causing the issue, maybe the system is too congested to meet the demand (this usually happens for modified test systems, since original test systems usually don’t have congestion).
If the minimum up and down time constraint is causing the infeasibility, maybe a generator cannot be turned up or down at a time that is necessary so the problem becomes infeasible.
These are just a few examples, because there are thousands of reasons that may cause infeasibility. You just need to analyze your specific case.
3. Fix the problem
Sometimes, the infeasibility is caused by an error in our code. For example, we might have used the wrong data for a certain constraint. In this case, we should fix our code.
Sometimes, the infeasibility is caused by the design of the test system. This is especially common if we modified the test system. Let’s say we reduced the capacity of a few transmission lines. Maybe that just makes the system infeasible. In this case, we should modify the test system. But keep in mind, if you modified the test system, please make sure you document what you changed from the original test system. This will be needed when we write a paper, because whenever we write about our simulation setup, we write about what test system we used and whether/how we modified it, so that if someone wants to repeat our simulation, they could get the same results as what we did.