0

Pleas help me. I want to use a set by not order elements as indexes of some

variables. for example

I have s=[2,3]

@constraint(ILRP,c7[ k=1:2,t=1:4],sum(x[i,j,k,t] for i=[2,3],

j=[2,3])<=size(s,1)-1)'

for index I ,j I want to use [2,3] as indexes. and I get for example this constraint:

x[2][2][k][t]+x[2][3][k][t]+x[3][2][k][t]+x[3][3][k][t]<=1

Thanks very much.

mbauman
  • 30,958
  • 4
  • 88
  • 123
Soma
  • 743
  • 6
  • 19
  • 1
    your constraint works correctly. What problem do you have? – Bogumił Kamiński Jan 08 '19 at 07:49
  • I have a set S=[[1, 2], [1, 3], [2, 3], [1, 2, 3]] I want use this set as indexes of my constraints. I coded that as follow: for i=1:size(S,1) a=size(S[i],1); b=S[i] @constraint(ILRP,c7[ k=1:2,t=1:4],sum(x[i,j,k,t] for i=b, j=b)<=a-1) end Thanks for your help. – Soma Jan 09 '19 at 18:36
  • 1
    This also looks good. – Bogumił Kamiński Jan 09 '19 at 18:42
  • only it takes time. how can I don't use loop for this constraint? – Soma Jan 09 '19 at 18:44
  • 1
    `@constraint(ILRP,c7[i=axes(S,1), k=1:2,t=1:4],sum(x[i,j,k,t] for i=S[i], j=S[i])<=length(S[i]-1)` should work but I have not checked. – Bogumił Kamiński Jan 09 '19 at 19:05
  • it is really useful. and it promotes my code. I am really thankful. but it has this error ERROR: MethodError: no method matching start(::AxisArrays.Axis{:row,Base.OneTo{Int64}}) – Soma Jan 10 '19 at 18:02
  • 1
    Can you please post a fully reproducible example as you seem to be using non standard arrays from a package. – Bogumił Kamiński Jan 10 '19 at 18:42
  • I couldn't post my code here. Because it is too long. Please if you could, say me another way that I can post my code for you. thank you for your kindly help. – Soma Jan 11 '19 at 16:20
  • I used "using JuMP,CPLEX,Combinatorics,Images" in top section. is that correct? should I use Images for axes()? – Soma Jan 11 '19 at 18:27
  • 1
    The easiest way to share larger portions of code is via https://gist.github.com/. You might try to convert images crated by Images to standard matrices (probably it is not needed, but Images can use custom indexing and it is a more advanced topic that). – Bogumił Kamiński Jan 12 '19 at 11:58
  • Thanks very much Prof. Kamiński . I registered there and placed the code. – Soma Jan 12 '19 at 15:43
  • can you add a link? – Bogumił Kamiński Jan 12 '19 at 16:58
  • sure. https://gist.github.com/soma903/459673eb112006aec1576896893a0106 – Soma Jan 12 '19 at 20:02
  • 1
    In this case `axes` should work as `S` is a standard array. I think that if you are not able to resolve it from this point it is better to switch to a chat-mode (e.g. ask a question on discourse). – Bogumił Kamiński Jan 13 '19 at 15:56
  • Thanks very much :) – Soma Jan 13 '19 at 20:47

0 Answers0