[AMPL 16036] Defining SOS1 Variables

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 16036] Defining SOS1 Variables

simon_onair
Dear all,

 I am trying to define a SOS1 variable (in my case: x) in AMPL to achieve better performance in branch&bound. Variable x is a binary variable that can only have one positive value for each i,q and t. k defines the discrete steps. I already have the constraint:

subject to x_bin{i in J, q in Q, t in T}: sum{k in K}x[i,q,t,k]=1;


I implemented the following to define SOS1:

suffix sosno integer IN;

suffix ref integer IN;


let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=i;

let {i in J, q in Q, t in T, k in K} x[i,q,t,k].ref:=k;


I have two problems:
1) AMPL tells me that "can't convert "itinerary1" to a number"
 What can I do? I don't want to rename the set of Itineraries (i) to a numbered set.
2) How can I define that for each i and q and t only one positive value can be assigned. Can I write the following?
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=i;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=q;

let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=t;



THANKS IN ADVANCE! :)

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 16041] Defining SOS1 Variables

AMPL mailing list
If J is your set of itineraries, define it as an ordered set to that you can use the ordinal position of each set member as your sosno value:

set J ordered;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno := ord(i);

However SOS1 formulations do not apply to the situation you describe, in which at most one x[i,q,t,k] can be 1 for each i, and also for each q, and also for each t.

In fact SOS1 is mainly useful for variables that are limited to an arbitrary set of values. In that case it's possible to write, for example, "var X {N} in S;" (where S is the set of possible values) and AMPL will automatically generate the corresponding SOS1 structure for the solver. For a further discussion see http://bob4er.blogspot.com/2013/04/special-sos-part-1.html.

--
Robert Fourer
[hidden email]
{#HS:551070518-4081#}
On Thu, Mar 29, 2018 at 2:44 PM UTC, <[hidden email]> wrote:
Dear all,

I am trying to define a SOS1 variable (in my case: x) in AMPL to achieve better performance in branch&bound. Variable x is a binary variable that can only have one positive value for each i,q and t. k defines the discrete steps. I already have the constraint:

subject to x_bin{i in J, q in Q, t in T}: sum{k in K}x[i,q,t,k]=1;

I implemented the following to define SOS1:
suffix sosno integer IN;

suffix ref integer IN;

let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=i;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].ref:=k;

I have two problems:
1) AMPL tells me that "can't convert "itinerary1" to a number"
What can I do? I don't want to rename the set of Itineraries (i) to a numbered set.
2) How can I define that for each i and q and t only one positive value can be assigned. Can I write the following?
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=i;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=q;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=t;

THANKS IN ADVANCE! :)



--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 16085] Defining SOS1 Variables

simon_onair
Thanks Mr. Fourer! 
Your Blog Post also helped me to better understand the idea behind SOS1! great :)

Am Freitag, 30. März 2018 15:58:33 UTC+2 schrieb AMPL Google Group:
If J is your set of itineraries, define it as an ordered set to that you can use the ordinal position of each set member as your sosno value:

set J ordered;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno := ord(i);

However SOS1 formulations do not apply to the situation you describe, in which at most one x[i,q,t,k] can be 1 for each i, and also for each q, and also for each t.

In fact SOS1 is mainly useful for variables that are limited to an arbitrary set of values. In that case it's possible to write, for example, "var X {N} in S;" (where S is the set of possible values) and AMPL will automatically generate the corresponding SOS1 structure for the solver. For a further discussion see <a href="http://bob4er.blogspot.com/2013/04/special-sos-part-1.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fbob4er.blogspot.com%2F2013%2F04%2Fspecial-sos-part-1.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-PNZTFNSVA1naPJtVzNwVyE73wA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fbob4er.blogspot.com%2F2013%2F04%2Fspecial-sos-part-1.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF-PNZTFNSVA1naPJtVzNwVyE73wA&#39;;return true;">http://bob4er.blogspot.com/2013/04/special-sos-part-1.html.

--
Robert Fourer
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="NdYdNt-rAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...
{#HS:551070518-4081#}
On Thu, Mar 29, 2018 at 2:44 PM UTC, <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="NdYdNt-rAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...> wrote:
Dear all,

I am trying to define a SOS1 variable (in my case: x) in AMPL to achieve better performance in branch&bound. Variable x is a binary variable that can only have one positive value for each i,q and t. k defines the discrete steps. I already have the constraint:

subject to x_bin{i in J, q in Q, t in T}: sum{k in K}x[i,q,t,k]=1;

I implemented the following to define SOS1:
suffix sosno integer IN;

suffix ref integer IN;

let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=i;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].ref:=k;

I have two problems:
1) AMPL tells me that "can't convert "itinerary1" to a number"
What can I do? I don't want to rename the set of Itineraries (i) to a numbered set.
2) How can I define that for each i and q and t only one positive value can be assigned. Can I write the following?
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=i;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=q;
let {i in J, q in Q, t in T, k in K} x[i,q,t,k].sosno:=t;

THANKS IN ADVANCE! :)



--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.