Loading ...
Sorry, an error occurred while loading the content.
 

Re: Function handling in netlogo

Expand Messages
  • andyfbraun
    as your request is formuated quite generally I can try to give you some hints: 1) give the turtles two variables: turtles-own [current-score previous-score]
    Message 1 of 4 , Feb 13, 2013
      as your request is formuated quite generally I can try to give you some hints:

      1) give the turtles two variables:
      turtles-own [current-score previous-score]

      2) create an input for a number in the interface (i.e. "score-factor"), so the user can enter one before running the model

      3) update the score according to the input and the previous score:
      to calculate-score
      ask turtles [
      set previous-score current-score
      set current-score previous-score * score-factor ; or any other equation
      end


      Maybe this is helpful in some way,

      Greets, Andreas Braun


      --- In netlogo-users@yahoogroups.com, "phat_cow2" wrote:
      >
      > I have a project that I am working on, and I wish to have a user defined function as a part of my program.
      > This function will be input by the user before the program begins, and the agents within the model will utilize this function to calculate their score at each tick.
      > However, at the moment, I do not know how to handle this function with respect to each agent.
      >
      > The function will use data from each iteration, and generate a score for each agent that they will then use for the following iteration.
      > Thank you for your help.
      >
      > Marcos Zuzuarregui
      > University of Arizona
      >
    • Luciano Cavaradossi
      Dear Jim, I just found your wonderful explanation of this important problem. Thank you, it really works! Could you please explain how to plot this
      Message 2 of 4 , Oct 10, 2015
        Dear Jim,

        I just found your wonderful explanation of this important problem. Thank you, it really works!

        Could you please explain how to plot this Scoring-Function?

        Thanks a lot!

        Luciano


        From: Jim Lyons <jimlyons@...>
        To: netlogo-users@yahoogroups.com
        Sent: Wednesday, February 13, 2013 10:24 AM
        Subject: Re: [netlogo-users] Function handling in netlogo

         
        On Feb 12, 2013, at 4:58 PM, phat_cow2 <phat_cow2@...> wrote:

        I have a project that I am working on, and I wish to have a user defined function as a part of my program. 
        This function will be input by the user before the program begins, and the agents within the model will utilize this function to calculate their score at each tick. 
        However, at the moment, I do not know how to handle this function with respect to each agent. 

        The function will use data from each iteration, and generate a score for each agent that they will then use for the following iteration.

        Marcos,
        Here is a trivial program that illustrates how a function can be entered into an input element and used in computations. For the test I made an input element named "Scoring-Function", set it to string reporter, either one-line or multi-line, and entered "energy - damage". You can see it work by pasting this into a new model and making settings and buttons as shown.

        ; settings -- view updates on ticks, 10 frames per second

        ; Interface Globals
        ;   Scoring-Function -- input, string reporter -- run by player 

        breed [ players player ]
          players-own [ energy damage score ]
          
        to initialize  ; by observer -- SETUP BUTTON
          clear-all
          create-players 20 [ init-player ]
          reset-ticks
        end

        to go  ; by observer, forever -- GO BUTTON
          if any? players with [energy <= 0] [ stop ]
          ask players [ go-player ]
          tick
        end

        ;--- PLAYERS ---
        to init-player  ; by player -- initialize
          set energy 100
          set damage 0
          set score run-result Scoring-Function
        end

        to go-player  ; by player -- advance one step
          right random 15  left random 15
          set score run-result Scoring-Function  ; compute new score
          fd score / 100
          set energy energy - 1  ; cost of moving
          if any? other players-here [ set damage damage + 1 ]  ; collision
        end

        Jim


      Your message has been successfully submitted and would be delivered to recipients shortly.