当前位置: 首页>>代码示例>>Java>>正文


Java Bag类代码示例

本文整理汇总了Java中sim.util.Bag的典型用法代码示例。如果您正苦于以下问题:Java Bag类的具体用法?Java Bag怎么用?Java Bag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Bag类属于sim.util包,在下文中一共展示了Bag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: placeMobileJammers

import sim.util.Bag; //导入依赖的package包/类
/**
 * Select adversarial nodes to be mobile jammers if needed.
 */
private void placeMobileJammers() {
  int numJammers = 0;
  Bag people = socialNetwork.getAllNodes();
  for (Object person : people) {
      if (((Person) person).trustPolicy == Person.TRUST_POLICY_ADVERSARY) {
          ((Person) person).trustPolicy = Person.TRUST_POLICY_ADVERSARY_JAMMER;
          System.err.println("Assigned node "+((Person) person).name + " to be a mobile jammer.");
          numJammers += 1;
      }
      if (numJammers >= NUMBER_OF_MOBILE_JAMMERS) {
          break;
      }
  }
  if (numJammers < NUMBER_OF_MOBILE_JAMMERS) {
      System.err.println("You don't have enough adversaries to establish this many mobile jammers. Please set the -na flag.");
  }
}
 
开发者ID:casific,项目名称:murmur,代码行数:21,代码来源:ProximitySimulation.java

示例2: addRandomSocialEdges

import sim.util.Bag; //导入依赖的package包/类
/**
 * Generate a random social graph that uniformly at random creates 5 edges for every node.
 */
private void addRandomSocialEdges() {
/** Adds a uniformly random social graph-- just picks 5 nodes for each node to be connected to */
  Bag people = socialNetwork.getAllNodes();
  for (Object person : people) {
    for (int i=0; i<5; i++) {
    // Choose a random second person.
    Object personB = null;
    do {
      personB = people.get(random.nextInt(people.numObjs));
    } while (person == personB);

    double buddiness = 1.0;
    socialNetwork.addEdge(person, personB, new Double(buddiness));
    // System.out.println(person + " is friends with " + personB);
    }
  }
}
 
开发者ID:casific,项目名称:murmur,代码行数:21,代码来源:ProximitySimulation.java

示例3: getFriends

import sim.util.Bag; //导入依赖的package包/类
/** Return a set containing the current person's friends in the social graph.
 */
public Set<Person> getFriends() {
  Bag myEdges = sim.socialNetwork.getEdges(this, null);
  Set<Person> friends = new HashSet<Person>();

  for (Object e1 : myEdges) {
    Person from = (Person) ((Edge) e1).from();
    Person to = (Person) ((Edge) e1).to();

    if (from == this) {
      friends.add(to);
    } else {
      friends.add(from);
    }
  }
  return friends;
}
 
开发者ID:casific,项目名称:murmur,代码行数:19,代码来源:Person.java

示例4: getSharedFriends

import sim.util.Bag; //导入依赖的package包/类
/** Return a set containing the common friend with "other". This would be handled by a 
 * PSI operation in practice.
 *
 * @param other The person with whom we should compute mutual friends.
 */
public Set<Object> getSharedFriends(Person other) {
  Bag myEdges = sim.socialNetwork.getEdges(this, null);
  Bag otherEdges = sim.socialNetwork.getEdges(other, null);

  Set<Object> sharedFriends = new HashSet<Object>();
  for (Object e1 : myEdges) {
    for (Object e2 : otherEdges) {
      // There has to be some way to do this more elegantly?
      Object myFrom = ((Edge) e1).from();
      Object myTo = ((Edge) e1).to();
      Object otherFrom = ((Edge) e2).from();
      Object otherTo = ((Edge) e2).to();

      Object myFriend = (myFrom == this) ? myTo : myFrom;
      Object otherFriend = (otherFrom == other) ? otherTo : otherFrom;

      // System.out.println(myFrom + " " + myTo + " " + otherFrom + " " + otherTo);
      if (myFriend == otherFriend) {
        sharedFriends.add(myFriend);
      }
    }
  }
  return sharedFriends;
}
 
开发者ID:casific,项目名称:murmur,代码行数:30,代码来源:Person.java

示例5: createToolTipText

import sim.util.Bag; //导入依赖的package包/类
public String createToolTipText( Rectangle2D.Double rect, final GUIState simulation )
{
String s = "<html><font face=\"" +
    getFont().getFamily() + "\" size=\"-1\">";
Bag[] hitObjects = objectsHitBy(rect);
int count = 0;
for(int x=0;x<hitObjects.length;x++)
    {
    FieldPortrayal2DHolder p = (FieldPortrayal2DHolder)(portrayals.get(x));
    for( int i = 0 ; i < hitObjects[x].numObjs ; i++ )
        {
        if (count > 0) s += "<br>";
        if (count >= MAX_TOOLTIP_LINES) { return s + "...<i>etc.</i></font></html>"; }
        count++;
        String status = p.portrayal.getStatus((LocationWrapper) (hitObjects[x].objs[i]));
        if (status != null) s += status;  // might return null, sort of meaning "leave me alone"
        }
    }
if (count==0) return null;
s += "</font></html>";
return s;
}
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:23,代码来源:Display2D.java

示例6: attach

import sim.util.Bag; //导入依赖的package包/类
/** A convenience function: creates a popup menu item of the given name which, when selected, will display the
    given inspector in the Console.  Used rarely, typically for per-field Inspectors. */
public void attach(final sim.portrayal.Inspector inspector, final String name)
    {
    JMenuItem consoleMenu = new JMenuItem("Show " + name);
    popup.add(consoleMenu);
    consoleMenu.addActionListener(new ActionListener()
        {
        public void actionPerformed(ActionEvent e)
            {
            Bag inspectors = new Bag();
            inspectors.add(inspector);
            Bag names = new Bag();
            names.add(name);
            simulation.controller.setInspectors(inspectors,names);
            }
        });
    }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:19,代码来源:Display2D.java

示例7: the

import sim.util.Bag; //导入依赖的package包/类
/** Returns LocationWrappers for all the objects which fall within the coordinate rectangle specified by rect.  This 
    rectangle is in the coordinate system of the (InnerDisplay2D) component inside the scroll
    view of the Display2D class.  The return value is an array of Bags.  For each FieldPortrayal
    attached to the Display2D, one Bag is returned holding all the LocationWrappers for objects falling within the
    rectangle which are associated with that FieldPortrayal's portrayed field.  The order of
    the Bags in the array is the same as the order of the FieldPortrayals in the Display2D's
    <code>portrayals</code> list.
*/
public Bag[] objectsHitBy( final Rectangle2D.Double rect )
    {
    Bag[] hitObjs = new Bag[portrayals.size()];
    Iterator iter = portrayals.iterator();
    int x=0;
            
    while (iter.hasNext())
        {
        hitObjs[x] = new Bag();
        FieldPortrayal2DHolder p = (FieldPortrayal2DHolder)(iter.next());
        if (p.visible)
            {
            p.portrayal.hitObjects(getDrawInfo2D(p, rect), hitObjs[x]);
            }
        x++;
        }
    return hitObjs;
    }
 
开发者ID:minhhn2910,项目名称:g-mason,代码行数:27,代码来源:Display2D.java

示例8: doesMatchCharacteristics

import sim.util.Bag; //导入依赖的package包/类
public boolean doesMatchCharacteristics(Bag c) {
    boolean result = false;
    // if both are null or empty, then return TRUE
    if ((c == null || c.numObjs == 0)
            && (relevantCharacteristics == null || relevantCharacteristics.numObjs == 0)) {
        result = true;
    } else {

        for (Object o1 : c) {
            for (Object o2 : relevantCharacteristics) {
                if (o1.getClass() == o2.getClass()) {
                    result = true;
                    break;
                }
            }
        }
    }
    return result;
}
 
开发者ID:woodrad,项目名称:MultiLab,代码行数:20,代码来源:Affordance.java

示例9: doesMatchCapabilities

import sim.util.Bag; //导入依赖的package包/类
public boolean doesMatchCapabilities(Bag c) {
    boolean result = false;
    // if both are null or empty, then return TRUE
    if ((c == null || c.numObjs == 0)
            && (relevantCapabilities == null || relevantCapabilities.numObjs == 0)) {
        result = true;
    } else {
        for (Object o1 : c) {
            for (Object o2 : relevantCapabilities) {
                if (o1.getClass() == o2.getClass()) {
                    result = true;
                    break;
                }
            }
        }
    }
    return result;
}
 
开发者ID:woodrad,项目名称:MultiLab,代码行数:19,代码来源:Affordance.java

示例10: Designer

import sim.util.Bag; //导入依赖的package包/类
public Designer(final SimpleConsumption simState, int dID, LabeledBag args, SparseGrid2D pGrid, SparseGrid2D cGrid, int distance) {
    this.setRNG(simState.random );
    this.setID(dID);
    this.targetProduct = new Bag();
    this.targetProduct = new Bag();
    this.setType(Designer.class);
    this.setShortDesc("Agent that is able to design products");
    Designing c = new Designing(simState.random);
    Bag cap = new Bag();
    cap.add(c);
    setMyCapabilities(cap);
    setInitialState("Ready to design a product");
    this.consGrid = cGrid;
    this.prodGrid = pGrid;
    
    // RUSS -- I'D RATHER NOT HAVE TO DO THIS INITIALIZATION HERE AND IN ALL PREDEFINED AGENTS
    intializeActionStep();
    
    taskArray[0] = new Task(Designing.class, targetProduct, args); // Design with no object (at this time) 
    
    action.initializeTaskList(taskArray);
}
 
开发者ID:woodrad,项目名称:MultiLab,代码行数:23,代码来源:Designer.java

示例11: LabourAndEmployment

import sim.util.Bag; //导入依赖的package包/类
private LabourAndEmployment(
   TimeseriesParameter<Double> labourToOffer,
   SimpleLabourMarket labourMarket,
   HouseholdDecisionRule labourWageAlgorithm
   ) {
   StateVerifier.checkNotNull(labourMarket, labourWageAlgorithm);
   this.labourToOffer = labourToOffer;
   this.labourMarket = labourMarket;
   this.labourOrderList = new Bag();
   this.labourEmployed = new LinkedList<Labour>();
   this.labourNotEmployed = labourToOffer.get();
   this.reservedLabourAmount = 0.;
   this.labourWageAlgorithm = labourWageAlgorithm;
   this.totalLabourAvailableThisCycle = labourToOffer.get();
   
   Simulation.repeat(this, "rememberState", NamedEventOrderings.AFTER_ALL);
   Simulation.repeat(this, "resetMemories", NamedEventOrderings.BEFORE_ALL);
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:19,代码来源:MacroHousehold.java

示例12: getMatchingCharacteristics

import sim.util.Bag; //导入依赖的package包/类
@Override
public Bag getMatchingCharacteristics(Bag characteristics){  
    // returns only those myCapabilities that match myCharacteristics
    Bag result = new Bag();
    Bag theseLabels = new Bag();
    for (int i = 0; i < characteristics.numObjs; i++){
        Characteristic ch = (Characteristic)characteristics.get(i);
        theseLabels.add(ch.getLabel());
    }
    for (int i = 0; i < theseLabels.numObjs; i++){
        Results findResult = myCharacteristics.get((String)theseLabels.get(i) ); 
        if (findResult.status.isCompleted()){
            result.add(findResult.getOutputs() );
        }
    }
    return result;
}
 
开发者ID:woodrad,项目名称:MultiLab,代码行数:18,代码来源:Interactor.java

示例13: MyHousehold

import sim.util.Bag; //导入依赖的package包/类
public MyHousehold(
    GoodsMarket goodsMarket,
    final String firstGoodType,
    final String secondGoodType
    ) {
    this.orderList = new Bag();
    this.assetList = new ArrayList<Contract>();
    Simulation.getSimState().schedule.scheduleOnce(this);
    this.goodsMarket = goodsMarket;
    
    cashLedger = new SimpleResourceInventory(100);
    goodsRepository = new SimpleGoodsRepository();
    
    this.firstGoodType = firstGoodType;
    this.secondGoodType = secondGoodType;
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:17,代码来源:GoodsMarketMatchingTest.java

示例14: ConsumptionAndGoods

import sim.util.Bag; //导入依赖的package包/类
private ConsumptionAndGoods(
   SimpleGoodsMarket goodsMarket,
   HouseholdDecisionRule consumptionBudgetAlgorithm,
   HouseholdConsumptionFunction consumptionFunction
   ) {
   StateVerifier.checkNotNull(goodsMarket, consumptionBudgetAlgorithm, consumptionFunction);
   this.goodsMarket = goodsMarket;
   this.goodsOrderList = new Bag();
   this.consumptionBudgetAllocationAlgorithm = consumptionBudgetAlgorithm;
   this.consumptionFunction = consumptionFunction;
   this.cashSpendOnGoodsThisBusinessCycle = 0.;
   this.lastPurchardGoodsVolumes = new HashMap<String, Double>();
   
   resetMemories();
   
   Simulation.repeat(this, "resetMemories", NamedEventOrderings.BEFORE_ALL);
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:18,代码来源:MacroHousehold.java

示例15: handleBankruptcy

import sim.util.Bag; //导入依赖的package包/类
@Override
public final void handleBankruptcy() {
   System.out.printf(
      "--------------------------------------------\n"
    + "Bank Bankrupty Event\n"
    + "Bank: " + getUniqueName() + "\n"
    + "--------------------------------------------\n"
    );
   
   bankruptcyResolutionPolicy.applyTo(this);
   
   if (centralBank != null) {
      CentralBankStrategy cbs = ((CentralBankStrategy) centralBank.getStrategy());
      Bag interventions = cbs.getCrisisInterventions();
      boolean isInList = false;
      for (int i = 0; i < interventions.size(); i++) {
         if (((Bank) interventions.get(i)).equals(this))
            isInList = true;
      }
      if (!isInList)
         interventions.add(this);
      cbs.setCrisisInterventions(interventions);
   }
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:25,代码来源:Bank.java


注:本文中的sim.util.Bag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。