2014-03-26 55 views
0

我一直在努力與這一個過去24小時左右,我覺得我錯過了這裏相對簡單的東西。優先附件:選擇要附加的節點

to setup-scale-free-network 

    clear-all 
    ;; Make a circle of turtles 
    set num-nodes (num-children + num-adults + num-toddlers) 
    create-children num-children 
    create-adults num-adults 
    create-toddlers num-toddlers 

    layout-circle turtles (max-pxcor - 8) 
    ask turtles[ 
    create-links-with turtles with [self > myself and random-float 5 < probability] 



    ] 
    setup 
end 

to-report find-partner 
    report [one-of both-ends] of one-of links 
end 

上面的代碼建立不同品種的海龜的一組數,並創建了若干這些品種之間的聯繫。

to go 
    reset-ticks 
    make-link find-partner 

    tick 
    end 

這兩個程序將被調用,直到滿足所需的程度分佈級別。

我想要做的就是使用查找合作伙伴程序轉向優先附件來執行此操作我需要修改此代碼以創建從節點查找夥伴已選擇到其他三種類型之一的鏈接的品種在我的網絡中。

to make-node [old-node] 
    crt 1 
    [ 
    set color red 
    if old-node != nobody 
     [ create-link-with old-node [ set color green ] 
     ;; position the new node near its partner 
     move-to old-node 
     fd 8 
     ] 
    ] 
end 

我自己的嘗試已經導致沒有誠實的地方。我知道我在尋求很多幫助,但我的智慧已經終結,謝謝你的幫助和耐心。

+0

您可能一次嘗試通過一次大的改變來學習太多。從工作代碼開始;做一個小改變,讓你走向正確的方向;讓這個變化起作用;試圖進一步的小改進,並得到這個工作;等等。如果在任何時候遇到困難,請到這裏,展示您的代碼,並詢問具體的問題。 –

回答

2

我無法完全理解你的問題。我猜你希望創建另一種類型的鏈接,你可以在已經是網絡一部分的海龜之間調用優先附件(綠色)。

在這種情況下你可能想要的一件事是,你不要選擇已經在優惠附件網絡中的烏龜。 [這只是我的假設]

我已修改您的代碼(如下)以獲得所需的網絡與綠色彩色鏈接顯示的優惠附件,已添加海龜變數already-attached這是用來排除已經優先附着於他人。

希望這會有所幫助!

breed [ children child ] 
breed [ adults adult ] 
breed [ toddlers toddler ] 

children-own [ already-attached ] 
adults-own [ already-attached ] 
toddlers-own [ already-attached ] 


to setup-scale-free-network 

    clear-all 
    let num-children 5 
    let num-adults 5 
    let num-toddlers 5 
    let probability 1 

    ;; Make a circle of turtles 

    create-children num-children [ set color orange ] 
    create-adults num-adults [ set color green ] 
    create-toddlers num-toddlers [ set color blue ] 

    layout-circle turtles (max-pxcor - 8) 
    ask turtles 
    [ 
    create-links-with turtles with [self > myself and random-float 5 < probability] 
    ] 

end 


to go 
    setup-scale-free-network 
    ask turtles with [already-attached = 0] 
    [ 
    attach-to-one-of-each-breed self 
    ] 
end 

to attach-to-one-of-each-breed [ source-node ] 
    ask source-node 
    [ 
     if any? other children with [ already-attached = 0 ] 
     [ 
     ask one-of other children 
     [ 
      set already-attached 1 
      create-link-with source-node [ set color green ] 
     ] 
     ] 

     if any? other adults with [ already-attached = 0 ] 
     [ 
     ask one-of other adults 
     [ 
      set already-attached 1 
      create-link-with source-node [ set color green ] 
     ] 
     ] 

     if any? other toddlers with [ already-attached = 0 ] 
     [ 
     ask one-of other toddlers 
     [ 
      set already-attached 1 
      create-link-with source-node [ set color green ] 
     ] 
     ] 
    ] 
end 
+1

小提示:我會使用'true'和'false'而不是'1'和'0'。 –