0

I have a set j and parameter edge. I have a graph too.

    Set j/1*5/;
   Alias(j,jp);

   Parameter edge(j,jp)

That edge(j,jp) =1 if there is arc from j to jp , and it's 0 if there isn't arc from j to jp. I maked edge(j,jp) .

I want to define a set or parameter , for saving index of neighborhood of node "j".

I Mean , neighborhood (j)={jp : edge(j,jp)=1}

I write ,below command but I get error.

  Set  neighborhood (j)
  Neighborhood (j)$edge (j,jp) =JP.val;

How can I obtain neighborhood of especial node?

Richard
  • 177
  • 1
  • 9

1 Answers1

1

Do you work with an directed graph and assume there is just one neighbor for each j? Then, try this:

Set j/1*3/;
Alias(j,jp);

Parameter edge(j,jp) / 1.2 1, 2.3 1, 3.1 1 /;

Parameter Neighborhood (j);
Neighborhood (j) = sum(jp$edge(j,jp), jp.val);

Otherwise: What do you expect to see in Neighborhood, if there is more than one neighbor?

Lutz
  • 2,197
  • 1
  • 10
  • 12
  • hello ,have a great day :-) . I want to have a set of all neighborhood of node j . for example if we have edge (1.2 ,1.3,1.6,1.10) in graph . then neighborhood ('1')={2,3,6,10} . – Richard Jul 30 '18 at 15:24
  • I can't give this set neighborhood (j)={jp : edge(j,jp)=1} , I try to use loop ، but again I don't have all neighborhood. – Richard Jul 30 '18 at 15:26
  • 1
    Like this? Set j/1*3/; Alias(j,jp); Parameter edge(j,jp) / 1.2 1, 2.3 1, 3.1 1 /; Parameter Neighborhood (j,jp); Neighborhood (j,jp)$edge(j,jp) = jp.val; – Lutz Jul 30 '18 at 19:55
  • thanks ,it's right ,but I want to have one index only . I write , Loop(j, neighborhood (j)$edge(j,jp)=jp.val. ); but in this situation ,I have errors in set jp . is it possible I have one index 'j' only ? – Richard Jul 31 '18 at 05:03
  • How do you want to store multiple values in one index? Neighborhood(j) can have exactly one value for each j, not more. – Lutz Jul 31 '18 at 07:14