So I have been working on a model that uses different linear constrains based on which binarie is activated. For my initial problem all the linear constrains are exactly the same one.

The problem works well and gives logical results, until I add a constrain that link all the binaries together and suddenly the solution has a lot of non-binaries values, between 0 and 1. I have never seen this problem before and haven't found yet a solution, so I come to see if someone has an answer here.

The code (more or less):

... (Declaring and defining values for most things)

forall(i in n) B(i) is_binary

forall(i in n) P(i)<= B(i)*Pmax !Only the P with the correct Binary will have a non-zero value

sum(P(1) + .. +P(n) + Pg - Pneg = Load) !the main contrain

sum(B(i)) <= 1 !So only 1 Binary (and thus linear constrain) is activated at the same time

forall(t in T) S(t) = S(t-1) + sum(P(1) + .. +P(n) - Pneg

forall(t in T) sum(B(i,s)*alfa_min(i,s)) <= S(t) <= sum(B(i,s)*alfa_max(i,s)) !This is the constraint that causes problems,which dictates the binary is active in each period.

When I add the last constrain, suddenly I get B(i) = 0.3 and other non-sense. I also see negative results for non-free varables

Any suggestion on how to deal with this problem or what I am doing wrong?

Have you checked the status of your problem before retrieving the solution values?

If you are working with Mosel, you could for example use code like the following:

!...solve...

if getprobstat<>XPRS_OPT then

writeln("No solution")

exit(0)

end-if

!...retrieve results...