2016-08-18 116 views
-1

我仍然遇到AnyLogic的麻煩......我正在開發一個流行SIRS模型,我想定義自己的網絡。AnyLogic - 自定義網絡

特別是,我有這個矩陣定義齡級 enter image description here

,所以我希望每個代理根據這個矩陣建立與其他藥劑接觸之間的接觸日均數......這是駕駛我瘋了:S

AgeClass是用下面的函數 enter image description here

我認爲設置,在用下面的代碼開始發生一次的事件計算的參數enter image description here

現在我說「N次連接到一個隨機代理」 ......我想說的是「次連接常與AgeClassķ隨機劑」是有辦法做到這一點?

感謝您的支持!

ps我寫的時候int i = AgeClass我拿了運行代碼的代理參數AgeClass的值,對吧?所以我對不同的代理人會有所不同?

回答

1

也許你已經找到了解決方案。這裏的方式做到這一點:

  1. 關於年齡,你並不需要那麼大的if/else如果序列。剛做這樣的事情:

int ageClass = 0; // a variable of agents ageClass = (int) floor(age/5.0); if (age >= 70.0) ageClass == 14; // just to be sure that max class is 14 return ageClass;

  • 關於網絡。我將創建一個名爲setup的函數,以便您可以在啓動時將其放入代理程序操作中。 setup();

  • 您可以創建一個鏈接到代理對象在代理級別(Person在我的代碼,我使用一個名爲接觸一個連接對象)。該功能會是這樣的:

  • // loop through age groups for (int i = 0; i < network[0].length; i++) { ArrayList<Person> ageGroupPeople = new ArrayList<Person>(); for (Person p : population) { if (p.ageClass == i) { ageGroupPeople.add(p) } \\ create pool of potential alters by age } \\ create network per agent for (Person ego : population) { for (int k = 0; k < poisson(network[ego.ageClass][i]); k++) { Person alter = randomFrom(ageGroupPeople); if (ego != alter) { ego.contacts.connectTo(alter);} } }

    我沒有檢查代碼,如何慢可能是,它僅僅是一個辦法做到這一點。