Binary Variable problem declaration

368 views
Skip to first unread message

Frederico Marques

unread,
Oct 28, 2021, 6:58:07 PM10/28/21
to AMPL Modeling Language
Hello Robert, 

I am working in an optmization problem, and I have a question about my binary variable.

In fact I have 2 question:

1º - I am working with an binary variable that is not working as a binary, when I change some parameters this variable stop working with 1 or 0. See below how I am using this one:

var y{Ol}, binary; --> This variable is to represent when a system have a key open or closed (1 for Closed and 0 for opened) but its not working;

2º - I have another variable that is totally connect with this binary one. When my key is Opened (0 Value)  this variable have to be a real number and when the key is closed must be zero (0) but its not working too. See below how I am woking with this one:

 subject to limite_chave1{(i,j) in Ol}:
      b[i,j] <= (Vmax^2-Vmin^2)*(1-y[i,j]);   
     
 subject to limite_chave2{(i,j) in Ol}:    
      b[i,j] >= -(Vmax^2-Vmin^2)*(1-y[i,j]);
 
Another observation is that this b[i,j] is connect with my tensions variables, so b[i,j] = V[j]^2 - V[i]^2 but when I declare this variable as an equation i got some errors, I tryed to make the equation as the following way:

var b{(i,j) in Ol} := V[j]^2 - V[i]^2

Can help me with these problems?

By the way thanks for your attention.

Best regards, 

Frederico Marques

AMPL Google Group

unread,
Nov 1, 2021, 10:12:09 AM11/1/21
to AMPL Modeling Language
It depends what you mean when you say that you have "a binary variable that is not working as a binary":
  • If the solver is giving you solutions that have fractional values (not 0 or 1) for your binary variable, then check that you are using a solver that can handle binary variables. For example, a message like "ignoring integrality of 21 variables" at the beginning of the solver run indicates that you're using a solver that cannot handle binary variables.
  • If the solver is giving you a solution that does not satisfy all of the limite_chave1 and limite_chave2 constraints, then check that the solver reported an "optimal solution". Other messages like "infeasible" or "unbounded" indicate that there's an error in your model that needs to be fixed.
To get more help, you'll need to give a more detailed explanation of when the binary variables are not working. Also, copy all of the output from your AMPL session -- everything you typed, and all the messages that AMPL and the solver displayed -- into your email. And if possible, also attach your files.


--
Robert Fourer
am...@googlegroups.com
{#HS:1679719276-106881#}

AMPL Google Group

unread,
Nov 1, 2021, 10:43:39 AM11/1/21
to AMPL Modeling Language
Also, in a variable definition, := only assigns an initial value. To define a variable by an expression involving other variables, use = instead:

var b {(i,j) in Ol} = V[j]^2 - V[i]^2;


--
Robert Fourer
am...@googlegroups.com
{#HS:1679719276-106881#}
On Mon, Nov 1, 2021 at 2:11 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
It depends what you mean when you say that you have "a binary variable that is not working as a binary":
  • If the solver is giving you solutions that have fractional values (not 0 or 1) for your binary variable, then check that you are using a solver that can handle binary variables. For example, a message like "ignoring integrality of 21 variables" at the beginning of the solver run indicates that you're using a solver that cannot handle binary variables.
  • If the solver is giving you a solution that does not satisfy all of the limite_chave1 and limite_chave2 constraints, then check that the solver reported an "optimal solution". Other messages like "infeasible" or "unbounded" indicate that there's an error in your model that needs to be fixed.
To get more help, you'll need to give a more detailed explanation of when the binary variables are not working. Also, copy all of the output from your AMPL session -- everything you typed, and all the messages that AMPL and the solver displayed -- into your email. And if possible, also attach your files.


--
Robert Fourer
am...@googlegroups.com
On Thu, Oct 28, 2021 at 10:58 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:

Frederico Costa

unread,
Nov 2, 2021, 10:39:29 AM11/2/21
to am...@googlegroups.com
Hi Robert,

First of all, thanks for your explanation.

I am using knitro solver so in my eyes it's possible that the problem is in my model.

I am attaching an image of my output with the solution. 

Unfortunately, I cannot attach my files yet because it is a Master's research that is in process.


--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/96y13ETQJrQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/reply-77152-1679719276-4921948628-1635775924-1048845163%40helpscout.net.


--

Frederico M. da Costa

Engenheiro Eletricista - UFG

Especialista em Sistemas Eletroenergéticos - IDS

Mestrando em Engenharia Elétrica - UFG

(62) 9 9428-3679

Objective Function.JPG

AMPL Google Group

unread,
Nov 2, 2021, 12:50:30 PM11/2/21
to AMPL Modeling Language
Your attached image shows that Knitro terminated normally, with a "locally optimal or satisfactory solution" and an objective value of 410734. Knitro can handle binary variables, so the solution returned by Knitro should have all binary variables at 0 or 1. Also the solution returned by Knitro should satisfy all of your constraints, including limite_chave1 and limite_chave2. So, can you explain now what is "not working" in your solution?


--
Robert Fourer
am...@googlegroups.com
{#HS:1679719276-106881#}
On Tue, Nov 2, 2021 at 2:39 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hi Robert,

First of all, thanks for your explanation.

I am using knitro solver so in my eyes it's possible that the problem is in my model.

I am attaching an image of my output with the solution.

Unfortunately, I cannot attach my files yet because it is a Master's research that is in process.

On Mon, Nov 1, 2021 at 2:43 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Also, in a variable definition, := only assigns an initial value. To define a variable by an expression involving other variables, use = instead:

var b {(i,j) in Ol} = V[j]^2 - V[i]^2;


--
Robert Fourer
am...@googlegroups.com
On Mon, Nov 1, 2021 at 2:11 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
It depends what you mean when you say that you have "a binary variable that is not working as a binary":
  • If the solver is giving you solutions that have fractional values (not 0 or 1) for your binary variable, then check that you are using a solver that can handle binary variables. For example, a message like "ignoring integrality of 21 variables" at the beginning of the solver run indicates that you're using a solver that cannot handle binary variables.
  • If the solver is giving you a solution that does not satisfy all of the limite_chave1 and limite_chave2 constraints, then check that the solver reported an "optimal solution". Other messages like "infeasible" or "unbounded" indicate that there's an error in your model that needs to be fixed.
To get more help, you'll need to give a more detailed explanation of when the binary variables are not working. Also, copy all of the output from your AMPL session -- everything you typed, and all the messages that AMPL and the solver displayed -- into your email. And if possible, also attach your files.


--
Robert Fourer
am...@googlegroups.com

Frederico Costa

unread,
Nov 3, 2021, 7:23:46 AM11/3/21
to am...@googlegroups.com
Hello Robert, 

When I said that it's not working it's because sometimes my variables weren't satisfying my constraints being 0 or 1 but after your explanations I think the error is in my variables model. 

Thank you a lot for your help!


--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/96y13ETQJrQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages