if nested??? [1 Attachment]

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

if nested??? [1 Attachment]

g_migs2004
Hello everyone, I am currently working on a project in which I think I have to put a series of nested if, which I have not been able to solve. I will put the problem and how I made the sentences which do not work.

 

 If your strategy k was 6, and there was interaction, you will keep your strategy the same, otherwise you will subtract -1 from your strategy.
 If your strategy k was -5, and there was interaction, your strategy will remain the same, otherwise +1 will be added to your strategy.
 If the agent's strategy k is between 1 and 5, and hub interaction, then +1 will be added to reinforce its strategy otherwise it will be subtracted -1 from its strategy.
 
 If the agent's strategy is between 0 to -4, and there was interaction, then -1 will be subtracted from his strategy, if the opposite happens then +1 will be added to his strategy.
 

 I put it in the following way

 

      if [k] of receptor = 6 [
         set k 6
       ]
       if [k] of receptor = -5 [
         set k -5
       ]
       if ([k] of receptor > 0) and ([k] of receptor < 6) [
         set k k + 1
       ]
       if ([k] of receptor <= 0) and ([k] of receptor > (0 - 5)) [
         set k k - 1
       ]
      if ([k] of receptor <= 0) [
         set k k + 1
       ]
       if ([k] of receptor > 0) [
         set k k - 1
       ]
 
     
 

 I will be very grateful if you could help me

 

Reply | Threaded
Open this post in threaded view
|

Re: if nested??? [1 Attachment]

guerrin
Hi,

the set of rules you want to implement is inconsistent.

For example :

if k > 6 OR k < 6 then k = k - 1

however

if k < - 4 OR k > 0 then k = k + 1

The first case applies to the second and vice-versa although k's
increments are opposite.

So first make your rule set consistent.

Second the set of rules expressed as natural language are not the same
as the ones written in NetLogo code.

Third, more generally, instead of writing :

   if [k] of receptor = 6... which will never be true since  [k] of
receptor is a list (of the values of all receptors -- I guess "receptor"
is an agenset) and 6 is a numerical value (even 6 and [6] cannot be equal)

better ask each receptor within the receptor agentset to modify its
strategy according to its current strategy value (I suppose receptors
own a k attribute) :

     to update-strategies

          ask receptors [

             ifelse k > -4 AND k < 0 [set k k - 1] [set k k + 1]

             ...]

     end

Hoping it will help you

cheers

FG



Le 29/06/2018 à 03:08, [hidden email] [netlogo-users] a écrit :

> [Attachment(s) <#TopText> from [hidden email] [netlogo-users]
> included below]
>
> Hello everyone, I am currently working on a project in which I think I
> have to put a series of nested if, which I have not been able to
> solve. I will put the problem and how I made the sentences which do
> not work.
>
>
> If your strategy k was 6, and there was interaction, you will keep
> your strategy the same, otherwise you will subtract -1 from your strategy.
>
> If your strategy k was -5, and there was interaction, your strategy
> will remain the same, otherwise +1 will be added to your strategy.
>
> If the agent's strategy k is between 1 and 5, and hub interaction,
> then +1 will be added to reinforce its strategy otherwise it will be
> subtracted -1 from its strategy.
>
> If the agent's strategy is between 0 to -4, and there was interaction,
> then -1 will be subtracted from his strategy, if the opposite happens
> then +1 will be added to his strategy.
>
>
> I put it in the following way
>
>
>      if [k] of receptor = 6 [
>
>         set k 6
>
>       ]
>
>       if [k] of receptor = -5 [
>
>         set k -5
>
>       ]
>
>       if ([k] of receptor > 0) and ([k] of receptor < 6) [
>
>         set k k + 1
>
>       ]
>
>       if ([k] of receptor <= 0) and ([k] of receptor > (0 - 5)) [
>
>         set k k - 1
>
>       ]
>
>  if ([k] of receptor <= 0) [
>
>         set k k + 1
>
>       ]
>
>       if ([k] of receptor > 0) [
>
>         set k k - 1
>
>       ]
>
>
> I will be very grateful if you could help me
>
>
>

--

SignatureMail-FG.png (33K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: if nested???

g_migs2004
Hello, thanks for answering
 

 Actually I was affirming twice since. I was asking the agents that are receptors to define their strategy, that was my mistake.
 

 I am already solved with the ideas you gave me
 

 regards
 

 MGSI