Reorganize agents and pallets





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have servers, pallets and tags breeds. Each server has a number of assigned pallets pallets-being-served and each pallet has an agentset of tags (tags-in-pallet ). All the tags assigned to a server are in the my-tags variable.



I have the following:



breed [ servers server ]
breed [ tags tag ]
breed [ pallets pallet ]

pallets-own [
tags-in-pallet
]

servers-own [
pallets-being-served
my-tags
]


to reorganization
let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
repeat num-changes-in-reorg [
let p1 nobody let p2 nobody let t1 nobody let t2 nobody
let my-pallets n-of 2 pallets ]
ask one-of my-pallets [
set p1 self
set p2 other my-pallets
set t1 [tags-in-pallet] of p1
set t2 [tags-in-pallet] of p2
]
ask p1 [ set tags-in-pallet t2 ]
ask p2 [ set tags-in-pallet t1 ]
ask servers [
set my-tags (turtle-set [ tags-in-pallet ] of pallets-being-served)
]
] ; repeat
end


The intention is to make some tags-in-pallet swaps between pairs of pallets and assign the changed tags to the corresponding server.
The above code seems to work, but It seems inelegant using auxiliary variables p1, p2, t1, t2. Besides, the ask servers clause involves all the servers when it is just necessary to refer to the servers where my-tags has changed.



Is there a better way to make the swap of tags and reassign them to there corresponding servers?



Regards










share|improve this question































    0















    I have servers, pallets and tags breeds. Each server has a number of assigned pallets pallets-being-served and each pallet has an agentset of tags (tags-in-pallet ). All the tags assigned to a server are in the my-tags variable.



    I have the following:



    breed [ servers server ]
    breed [ tags tag ]
    breed [ pallets pallet ]

    pallets-own [
    tags-in-pallet
    ]

    servers-own [
    pallets-being-served
    my-tags
    ]


    to reorganization
    let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
    repeat num-changes-in-reorg [
    let p1 nobody let p2 nobody let t1 nobody let t2 nobody
    let my-pallets n-of 2 pallets ]
    ask one-of my-pallets [
    set p1 self
    set p2 other my-pallets
    set t1 [tags-in-pallet] of p1
    set t2 [tags-in-pallet] of p2
    ]
    ask p1 [ set tags-in-pallet t2 ]
    ask p2 [ set tags-in-pallet t1 ]
    ask servers [
    set my-tags (turtle-set [ tags-in-pallet ] of pallets-being-served)
    ]
    ] ; repeat
    end


    The intention is to make some tags-in-pallet swaps between pairs of pallets and assign the changed tags to the corresponding server.
    The above code seems to work, but It seems inelegant using auxiliary variables p1, p2, t1, t2. Besides, the ask servers clause involves all the servers when it is just necessary to refer to the servers where my-tags has changed.



    Is there a better way to make the swap of tags and reassign them to there corresponding servers?



    Regards










    share|improve this question



























      0












      0








      0








      I have servers, pallets and tags breeds. Each server has a number of assigned pallets pallets-being-served and each pallet has an agentset of tags (tags-in-pallet ). All the tags assigned to a server are in the my-tags variable.



      I have the following:



      breed [ servers server ]
      breed [ tags tag ]
      breed [ pallets pallet ]

      pallets-own [
      tags-in-pallet
      ]

      servers-own [
      pallets-being-served
      my-tags
      ]


      to reorganization
      let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
      repeat num-changes-in-reorg [
      let p1 nobody let p2 nobody let t1 nobody let t2 nobody
      let my-pallets n-of 2 pallets ]
      ask one-of my-pallets [
      set p1 self
      set p2 other my-pallets
      set t1 [tags-in-pallet] of p1
      set t2 [tags-in-pallet] of p2
      ]
      ask p1 [ set tags-in-pallet t2 ]
      ask p2 [ set tags-in-pallet t1 ]
      ask servers [
      set my-tags (turtle-set [ tags-in-pallet ] of pallets-being-served)
      ]
      ] ; repeat
      end


      The intention is to make some tags-in-pallet swaps between pairs of pallets and assign the changed tags to the corresponding server.
      The above code seems to work, but It seems inelegant using auxiliary variables p1, p2, t1, t2. Besides, the ask servers clause involves all the servers when it is just necessary to refer to the servers where my-tags has changed.



      Is there a better way to make the swap of tags and reassign them to there corresponding servers?



      Regards










      share|improve this question
















      I have servers, pallets and tags breeds. Each server has a number of assigned pallets pallets-being-served and each pallet has an agentset of tags (tags-in-pallet ). All the tags assigned to a server are in the my-tags variable.



      I have the following:



      breed [ servers server ]
      breed [ tags tag ]
      breed [ pallets pallet ]

      pallets-own [
      tags-in-pallet
      ]

      servers-own [
      pallets-being-served
      my-tags
      ]


      to reorganization
      let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
      repeat num-changes-in-reorg [
      let p1 nobody let p2 nobody let t1 nobody let t2 nobody
      let my-pallets n-of 2 pallets ]
      ask one-of my-pallets [
      set p1 self
      set p2 other my-pallets
      set t1 [tags-in-pallet] of p1
      set t2 [tags-in-pallet] of p2
      ]
      ask p1 [ set tags-in-pallet t2 ]
      ask p2 [ set tags-in-pallet t1 ]
      ask servers [
      set my-tags (turtle-set [ tags-in-pallet ] of pallets-being-served)
      ]
      ] ; repeat
      end


      The intention is to make some tags-in-pallet swaps between pairs of pallets and assign the changed tags to the corresponding server.
      The above code seems to work, but It seems inelegant using auxiliary variables p1, p2, t1, t2. Besides, the ask servers clause involves all the servers when it is just necessary to refer to the servers where my-tags has changed.



      Is there a better way to make the swap of tags and reassign them to there corresponding servers?



      Regards







      netlogo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 21:37







      user1993416

















      asked Nov 16 '18 at 19:41









      user1993416user1993416

      324112




      324112
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Are there any restrictions on tags? I am not entirely clear what you are doing, but it seems to me that the easiest way to do what I think you want to do is simply choose n-of from each pallet, remove these from the pallets you took them from and add them to the other pallet. If this is a correct interpretation, you want something like (note, not tested and will definitely be wrong):



          to reorganization
          let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
          let p1 one-of pallets
          let p2 one-of pallets with [not member? self p1]
          let p1-to-p2 n-of num-changes-in-reorg [tags] of p1
          let p2-to-p1 n-of num-changes-in-reorg [tags] of p2
          ask p1 [set tags (turtle-set tags with [not member? self p1-to-p2] p2-to-p1]
          ask p2 [set tags (turtle-set tags with [not member? self p2-to-p1] p1-to-p2]
          end


          I haven't answered the server bit as I am not clear how the servers and pallets connect.






          share|improve this answer
























          • Thank you. Your approach is to take some of the tags from one pallet to another. I must say that the code is beautiful. My system has servers and each of them has e.g. 9 pallets assigned. My code tries to inter-exchange (to shuffle :-) pairs of pallets in the warehouse (I repeat this num-changes-in-reorg times). The trick is that I do not change the pallets I just swap their content (all the tags in the pallet). The reason is that each pallet has a location in the warehouse and if I only move the content of the pallet I can neglect the location of pallets.

            – user1993416
            Nov 17 '18 at 9:19













          • in the process of swapping the pallet contents, I have to update the server's my-tags variable with all the tags assigned to the server involved in the change.

            – user1993416
            Nov 17 '18 at 9:21













          • I should only update the my-tagsvariable of the concerned servers in the swap of tags.

            – user1993416
            Nov 17 '18 at 9:30











          • I am still unclear what you are trying to do. Why can't you simply swap the location values of the pair of pallets?

            – JenB
            Nov 17 '18 at 15:13











          • you are right, it is not clear. If the reader is placed in (0,0) the pallets are placed at (0,0), (-1,0), (1, 0), (0,-1), (0,1), (1,1), (-1,1), (-1,-1), (1,-1). Are variables of pallets breed dx-to-center-of-reader, dy-to-center-of-reader. Each server has the same number of pallets, some has tags other might be empty.

            – user1993416
            Nov 17 '18 at 16:38












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344352%2freorganize-agents-and-pallets%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Are there any restrictions on tags? I am not entirely clear what you are doing, but it seems to me that the easiest way to do what I think you want to do is simply choose n-of from each pallet, remove these from the pallets you took them from and add them to the other pallet. If this is a correct interpretation, you want something like (note, not tested and will definitely be wrong):



          to reorganization
          let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
          let p1 one-of pallets
          let p2 one-of pallets with [not member? self p1]
          let p1-to-p2 n-of num-changes-in-reorg [tags] of p1
          let p2-to-p1 n-of num-changes-in-reorg [tags] of p2
          ask p1 [set tags (turtle-set tags with [not member? self p1-to-p2] p2-to-p1]
          ask p2 [set tags (turtle-set tags with [not member? self p2-to-p1] p1-to-p2]
          end


          I haven't answered the server bit as I am not clear how the servers and pallets connect.






          share|improve this answer
























          • Thank you. Your approach is to take some of the tags from one pallet to another. I must say that the code is beautiful. My system has servers and each of them has e.g. 9 pallets assigned. My code tries to inter-exchange (to shuffle :-) pairs of pallets in the warehouse (I repeat this num-changes-in-reorg times). The trick is that I do not change the pallets I just swap their content (all the tags in the pallet). The reason is that each pallet has a location in the warehouse and if I only move the content of the pallet I can neglect the location of pallets.

            – user1993416
            Nov 17 '18 at 9:19













          • in the process of swapping the pallet contents, I have to update the server's my-tags variable with all the tags assigned to the server involved in the change.

            – user1993416
            Nov 17 '18 at 9:21













          • I should only update the my-tagsvariable of the concerned servers in the swap of tags.

            – user1993416
            Nov 17 '18 at 9:30











          • I am still unclear what you are trying to do. Why can't you simply swap the location values of the pair of pallets?

            – JenB
            Nov 17 '18 at 15:13











          • you are right, it is not clear. If the reader is placed in (0,0) the pallets are placed at (0,0), (-1,0), (1, 0), (0,-1), (0,1), (1,1), (-1,1), (-1,-1), (1,-1). Are variables of pallets breed dx-to-center-of-reader, dy-to-center-of-reader. Each server has the same number of pallets, some has tags other might be empty.

            – user1993416
            Nov 17 '18 at 16:38
















          2














          Are there any restrictions on tags? I am not entirely clear what you are doing, but it seems to me that the easiest way to do what I think you want to do is simply choose n-of from each pallet, remove these from the pallets you took them from and add them to the other pallet. If this is a correct interpretation, you want something like (note, not tested and will definitely be wrong):



          to reorganization
          let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
          let p1 one-of pallets
          let p2 one-of pallets with [not member? self p1]
          let p1-to-p2 n-of num-changes-in-reorg [tags] of p1
          let p2-to-p1 n-of num-changes-in-reorg [tags] of p2
          ask p1 [set tags (turtle-set tags with [not member? self p1-to-p2] p2-to-p1]
          ask p2 [set tags (turtle-set tags with [not member? self p2-to-p1] p1-to-p2]
          end


          I haven't answered the server bit as I am not clear how the servers and pallets connect.






          share|improve this answer
























          • Thank you. Your approach is to take some of the tags from one pallet to another. I must say that the code is beautiful. My system has servers and each of them has e.g. 9 pallets assigned. My code tries to inter-exchange (to shuffle :-) pairs of pallets in the warehouse (I repeat this num-changes-in-reorg times). The trick is that I do not change the pallets I just swap their content (all the tags in the pallet). The reason is that each pallet has a location in the warehouse and if I only move the content of the pallet I can neglect the location of pallets.

            – user1993416
            Nov 17 '18 at 9:19













          • in the process of swapping the pallet contents, I have to update the server's my-tags variable with all the tags assigned to the server involved in the change.

            – user1993416
            Nov 17 '18 at 9:21













          • I should only update the my-tagsvariable of the concerned servers in the swap of tags.

            – user1993416
            Nov 17 '18 at 9:30











          • I am still unclear what you are trying to do. Why can't you simply swap the location values of the pair of pallets?

            – JenB
            Nov 17 '18 at 15:13











          • you are right, it is not clear. If the reader is placed in (0,0) the pallets are placed at (0,0), (-1,0), (1, 0), (0,-1), (0,1), (1,1), (-1,1), (-1,-1), (1,-1). Are variables of pallets breed dx-to-center-of-reader, dy-to-center-of-reader. Each server has the same number of pallets, some has tags other might be empty.

            – user1993416
            Nov 17 '18 at 16:38














          2












          2








          2







          Are there any restrictions on tags? I am not entirely clear what you are doing, but it seems to me that the easiest way to do what I think you want to do is simply choose n-of from each pallet, remove these from the pallets you took them from and add them to the other pallet. If this is a correct interpretation, you want something like (note, not tested and will definitely be wrong):



          to reorganization
          let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
          let p1 one-of pallets
          let p2 one-of pallets with [not member? self p1]
          let p1-to-p2 n-of num-changes-in-reorg [tags] of p1
          let p2-to-p1 n-of num-changes-in-reorg [tags] of p2
          ask p1 [set tags (turtle-set tags with [not member? self p1-to-p2] p2-to-p1]
          ask p2 [set tags (turtle-set tags with [not member? self p2-to-p1] p1-to-p2]
          end


          I haven't answered the server bit as I am not clear how the servers and pallets connect.






          share|improve this answer













          Are there any restrictions on tags? I am not entirely clear what you are doing, but it seems to me that the easiest way to do what I think you want to do is simply choose n-of from each pallet, remove these from the pallets you took them from and add them to the other pallet. If this is a correct interpretation, you want something like (note, not tested and will definitely be wrong):



          to reorganization
          let num-changes-in-reorg (random (num-pallets-by-side ^ 2 - 1) + 1) ; the num of changes
          let p1 one-of pallets
          let p2 one-of pallets with [not member? self p1]
          let p1-to-p2 n-of num-changes-in-reorg [tags] of p1
          let p2-to-p1 n-of num-changes-in-reorg [tags] of p2
          ask p1 [set tags (turtle-set tags with [not member? self p1-to-p2] p2-to-p1]
          ask p2 [set tags (turtle-set tags with [not member? self p2-to-p1] p1-to-p2]
          end


          I haven't answered the server bit as I am not clear how the servers and pallets connect.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 23:23









          JenBJenB

          9,07511036




          9,07511036













          • Thank you. Your approach is to take some of the tags from one pallet to another. I must say that the code is beautiful. My system has servers and each of them has e.g. 9 pallets assigned. My code tries to inter-exchange (to shuffle :-) pairs of pallets in the warehouse (I repeat this num-changes-in-reorg times). The trick is that I do not change the pallets I just swap their content (all the tags in the pallet). The reason is that each pallet has a location in the warehouse and if I only move the content of the pallet I can neglect the location of pallets.

            – user1993416
            Nov 17 '18 at 9:19













          • in the process of swapping the pallet contents, I have to update the server's my-tags variable with all the tags assigned to the server involved in the change.

            – user1993416
            Nov 17 '18 at 9:21













          • I should only update the my-tagsvariable of the concerned servers in the swap of tags.

            – user1993416
            Nov 17 '18 at 9:30











          • I am still unclear what you are trying to do. Why can't you simply swap the location values of the pair of pallets?

            – JenB
            Nov 17 '18 at 15:13











          • you are right, it is not clear. If the reader is placed in (0,0) the pallets are placed at (0,0), (-1,0), (1, 0), (0,-1), (0,1), (1,1), (-1,1), (-1,-1), (1,-1). Are variables of pallets breed dx-to-center-of-reader, dy-to-center-of-reader. Each server has the same number of pallets, some has tags other might be empty.

            – user1993416
            Nov 17 '18 at 16:38



















          • Thank you. Your approach is to take some of the tags from one pallet to another. I must say that the code is beautiful. My system has servers and each of them has e.g. 9 pallets assigned. My code tries to inter-exchange (to shuffle :-) pairs of pallets in the warehouse (I repeat this num-changes-in-reorg times). The trick is that I do not change the pallets I just swap their content (all the tags in the pallet). The reason is that each pallet has a location in the warehouse and if I only move the content of the pallet I can neglect the location of pallets.

            – user1993416
            Nov 17 '18 at 9:19













          • in the process of swapping the pallet contents, I have to update the server's my-tags variable with all the tags assigned to the server involved in the change.

            – user1993416
            Nov 17 '18 at 9:21













          • I should only update the my-tagsvariable of the concerned servers in the swap of tags.

            – user1993416
            Nov 17 '18 at 9:30











          • I am still unclear what you are trying to do. Why can't you simply swap the location values of the pair of pallets?

            – JenB
            Nov 17 '18 at 15:13











          • you are right, it is not clear. If the reader is placed in (0,0) the pallets are placed at (0,0), (-1,0), (1, 0), (0,-1), (0,1), (1,1), (-1,1), (-1,-1), (1,-1). Are variables of pallets breed dx-to-center-of-reader, dy-to-center-of-reader. Each server has the same number of pallets, some has tags other might be empty.

            – user1993416
            Nov 17 '18 at 16:38

















          Thank you. Your approach is to take some of the tags from one pallet to another. I must say that the code is beautiful. My system has servers and each of them has e.g. 9 pallets assigned. My code tries to inter-exchange (to shuffle :-) pairs of pallets in the warehouse (I repeat this num-changes-in-reorg times). The trick is that I do not change the pallets I just swap their content (all the tags in the pallet). The reason is that each pallet has a location in the warehouse and if I only move the content of the pallet I can neglect the location of pallets.

          – user1993416
          Nov 17 '18 at 9:19







          Thank you. Your approach is to take some of the tags from one pallet to another. I must say that the code is beautiful. My system has servers and each of them has e.g. 9 pallets assigned. My code tries to inter-exchange (to shuffle :-) pairs of pallets in the warehouse (I repeat this num-changes-in-reorg times). The trick is that I do not change the pallets I just swap their content (all the tags in the pallet). The reason is that each pallet has a location in the warehouse and if I only move the content of the pallet I can neglect the location of pallets.

          – user1993416
          Nov 17 '18 at 9:19















          in the process of swapping the pallet contents, I have to update the server's my-tags variable with all the tags assigned to the server involved in the change.

          – user1993416
          Nov 17 '18 at 9:21







          in the process of swapping the pallet contents, I have to update the server's my-tags variable with all the tags assigned to the server involved in the change.

          – user1993416
          Nov 17 '18 at 9:21















          I should only update the my-tagsvariable of the concerned servers in the swap of tags.

          – user1993416
          Nov 17 '18 at 9:30





          I should only update the my-tagsvariable of the concerned servers in the swap of tags.

          – user1993416
          Nov 17 '18 at 9:30













          I am still unclear what you are trying to do. Why can't you simply swap the location values of the pair of pallets?

          – JenB
          Nov 17 '18 at 15:13





          I am still unclear what you are trying to do. Why can't you simply swap the location values of the pair of pallets?

          – JenB
          Nov 17 '18 at 15:13













          you are right, it is not clear. If the reader is placed in (0,0) the pallets are placed at (0,0), (-1,0), (1, 0), (0,-1), (0,1), (1,1), (-1,1), (-1,-1), (1,-1). Are variables of pallets breed dx-to-center-of-reader, dy-to-center-of-reader. Each server has the same number of pallets, some has tags other might be empty.

          – user1993416
          Nov 17 '18 at 16:38





          you are right, it is not clear. If the reader is placed in (0,0) the pallets are placed at (0,0), (-1,0), (1, 0), (0,-1), (0,1), (1,1), (-1,1), (-1,-1), (1,-1). Are variables of pallets breed dx-to-center-of-reader, dy-to-center-of-reader. Each server has the same number of pallets, some has tags other might be empty.

          – user1993416
          Nov 17 '18 at 16:38




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344352%2freorganize-agents-and-pallets%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine