| ²é¿´: 804 | »Ø¸´: 1 | ||
water11½ð³æ (ÕýʽдÊÖ)
|
[ÇóÖú]
Java³ÌÐòûÓдíÎ󣬵«²»ÏÔʾ½á¹û£¬ÇóÖ¸µã¡£ ÒÑÓÐ1È˲ÎÓë
|
|
java³ÌÐòÔËÐУ¨»·¾³Eclipse£©Ê±Ã»ÓÐÌáʾ´íÎó, µ«ÊDz»ÏÔʾ½á¹û£¬²»Ã÷ËùÒÔ£¬Çë´ó¼Ò°ï°ï棬·Ç³£¸Ðл¡£ Person.java´úÂëÈçÏ£º public class Person { private boolean IsConsuming; private boolean IsConcerned; private int LastTimeChangeConcernedFromConsumingToNonConsuming; private ContinuousSpace <Object> mySpace; // handle for the space public Person(ContinuousSpace <Object> space, boolean consuming, boolean concerned){ IsConsuming=consuming; IsConcerned=concerned; mySpace = space; LastTimeChangeConcernedFromConsumingToNonConsuming = 0; } @ScheduledMethod (start=1, interval=1 ) public void step () { LastTimeChangeConcernedFromConsumingToNonConsuming++; } private void NonConcernedChangeFromConsumingToNonConsuming () { if (IsConcerned == false) { double rnd = RandomHelper.nextDouble(); if (rnd < 0.1) { IsConsuming = !IsConsuming; } } } private void ConsumingChangeFromNonConcernedToConcerned () { if (IsConcerned == false) { Context <Object> context = ContextUtils.getContext(this); Network <Object> net = (Network<Object> context.getProjection ("communication" ;Iterable<Object> neighbours = net.getAdjacent(this); for (Object obj : neighbours) { boolean neighbourConcernStatus = ((Person) obj).GetConcernStatus(); if (neighbourConcernStatus == true) { IsConcerned = true; } } } } private void ConcernedChangeFromConsumingToConsuming () { if ((IsConcerned == true) && (IsConsuming == true)) { Context <Object> context = ContextUtils.getContext(this); Network <Object> net = (Network<Object> context.getProjection ("communication" ;int number_of_neighbours = 0; int number_of_noncons = 0; Iterable<Object> neighbours = net.getAdjacent(this); for (Object obj : neighbours) { number_of_neighbours++; boolean neighbourConsumingStatus = ((Person) obj).GetConsumingStatus(); if (neighbourConsumingStatus == false) { number_of_noncons++; } } if (number_of_noncons == number_of_neighbours) { IsConsuming = false; LastTimeChangeConcernedFromConsumingToNonConsuming = 0; } } } private void NonConsumingChangeFromConcernedToNonConcerned () { if ((IsConcerned == true) && (IsConsuming ==false) && (LastTimeChangeConcernedFromConsumingToNonConsuming > 20)) { IsConcerned = false; } } public boolean GetConcernStatus() { return IsConcerned; } public boolean GetConsumingStatus() { return IsConsuming; } } MyStyle.java´úÂëÈçÏ£º public class MyStyle extends DefaultStyleOGL2D { @Override public Color getColor(Object obj) { if (obj instanceof Person) { Person agent = (Person) obj; if (agent.GetConsumingStatus() == true) { return Color.BLUE; } else { return Color.RED; } } else { return null; } } @Override public VSpatial getVSpatial(Object obj, VSpatial shape) { if (obj instanceof Person) { Person agent = (Person) obj; if (agent.GetConcernStatus() == true) { // consuming return shapeFactory.createRectangle(10, 10); // cubic } else { return shapeFactory.createCircle(3, 10); } } else { return null; } } } MyContextBuilder.java´úÂëÈçÏ£º public class MyContextBuilder implements ContextBuilder<Object> { public Context build(Context<Object> context) { ContinuousSpaceFactory spaceFactory = ContinuousSpaceFactoryFinder.createContinuousSpaceFactory(null); ContinuousSpace <Object> space = spaceFactory.createContinuousSpace ("space", context, new SimpleCartesianAdder<Object>(), new repast.simphony.space.continuous.WrapAroundBorders(), new double[]{1, 1}); for (int i=1; i<=3; i++){ Person p = new Person(space, true, true); context.add(p); } for (int i=1; i<=3; i++){ Person p = new Person(space, true, false); context.add(p); } for (int i=1; i<=47; i++){ Person p = new Person(space, true, false); context.add(p); } for (int i=1; i<=47; i++){ Person p = new Person(space, false, false); context.add(p); } // create network projection NetworkBuilder <Object> netBuilder = new NetworkBuilder<Object>("communication", context, false); NetworkGenerator gen; gen = new WattsBetaSmallWorldGenerator(0.25, 8, false); // prob connected, degree, symmetrical = false netBuilder.setGenerator(gen); netBuilder.buildNetwork(); RunEnvironment.getInstance().endAt(1000); return context; } } |
» ²ÂÄãϲ»¶
ÉúÎïѧµ÷¼Á
ÒѾÓÐ10È˻ظ´
Çóµ÷¼Á
ÒѾÓÐ3È˻ظ´
320Çóµ÷¼Á
ÒѾÓÐ5È˻ظ´
½ÓÊÜÈκε÷¼Á
ÒѾÓÐ7È˻ظ´
»¯Ñ§070300 Çóµ÷¼Á
ÒѾÓÐ29È˻ظ´
297£¬¹¤¿Æµ÷¼Á?
ÒѾÓÐ5È˻ظ´
22408 312Çóµ÷¼Á
ÒѾÓÐ26È˻ظ´
ÊÕµ½¸´ÊÔµ÷¼Áµ«ÊÇÈ¥²»ÁË
ÒѾÓÐ8È˻ظ´
260Çóµ÷¼Á
ÒѾÓÐ5È˻ظ´
¼±Ðèµ÷¼Á
ÒѾÓÐ10È˻ظ´
» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:
²ËÄñÇóÖú£¬ÀÏʦ¸øÁËÒ»¸ö·Ö×ÓÈÃÓÅ»¯£¬¿É×ÜÊÇ´íÎó£¬Çó´óÉñÖ¸µã
ÒѾÓÐ22È˻ظ´
ÇóÖ¸µã£ºjava web serivce ѧϰÄǸö¹¤¾ß£¿
ÒѾÓÐ4È˻ظ´
matlab³ÌÐòÔËÐÐ×ÜÊdzöÏÖÏÂÃæµÄ´íÎó£¬Çë¸÷λ¸ßÊÖÖ¸µãһϣ¬Ð»Ð»ÁË£¡¼± ¼±¼±
ÒѾÓÐ5È˻ظ´
¡¾ÇóÖú¡¿Çë¸ßÊÖÖ¸µãÒ»ÏÂvc++µÄÒ»²¿·Ö³ÌÐò£¬¿´¿´ÄÄÓдíÎ󣬼±¼±¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£
ÒѾÓÐ6È˻ظ´
erghper
ͳæ (СÓÐÃûÆø)
- Ó¦Öú: 3 (Ó×¶ùÔ°)
- ½ð±Ò: 1419.8
- ºì»¨: 1
- Ìû×Ó: 141
- ÔÚÏß: 44.8Сʱ
- ³æºÅ: 1146544
- ×¢²á: 2010-11-14
- ÐÔ±ð: GG
- רҵ: Ô×ӺͷÖ×ÓÎïÀí
2Â¥2014-11-18 09:13:48













context.getProjection ("communication"
»Ø¸´´ËÂ¥
20