private static int buildRings( final IScope scope, final IAgentFilter filter, final Double distance, final List<Double> rings, final Map<Double, Integer> ringsPn, final IAddressableContainer<Integer, IAgent, Integer, IAgent> agents) { IList<ILocation> locs = GamaListFactory.create(Types.POINT); for (IAgent ag : agents.iterable(scope)) { locs.add(ag.getLocation()); } ILocation centralLoc = (ILocation) Stats.getMean(scope, locs); IAgent centralAg = scope.getTopology().getAgentClosestTo(scope, centralLoc, filter); List<IAgent> neighbors = distance == 0 || filter == null ? new ArrayList<IAgent>() : new ArrayList<IAgent>( scope.getTopology().getNeighborsOf(scope, centralAg, distance, filter)); for (IAgent ag : neighbors) { double dist = centralLoc.euclidianDistanceTo(ag.getLocation()); if (dist == 0) { continue; } if (!rings.contains(dist)) { rings.add(dist); ringsPn.put(dist, 1); } else { ringsPn.put(dist, 1 + ringsPn.get(dist)); } } Collections.sort(rings); for (int i = 1; i < rings.size(); i++) { double dist = rings.get(i); double dist1 = rings.get(i - 1); ringsPn.put(dist, ringsPn.get(dist) + ringsPn.get(dist1)); } return rings.size(); }
private static void computeXaXsTransitions( final IScope scope, final IAgentFilter filter, final GamaMatrix<Double> fuzzytransitions, final Double distance, final IContainer<Integer, IAgent> agents, final int nbCat, final Map<List<Integer>, Map<Double, Double>> XaPerTransition, final Map<List<Integer>, Map<Double, Double>> XsPerTransition, final Set<Double> Xvals) { IList<ILocation> locs = GamaListFactory.create(Types.POINT); for (IAgent ag : agents.iterable(scope)) { locs.add(ag.getLocation()); } ILocation centralLoc = (ILocation) Stats.getMean(scope, locs); if (filter != null) { IAgent centralAg = scope.getTopology().getAgentClosestTo(scope, centralLoc, filter); List<IAgent> neighbors = distance == 0 ? new ArrayList<IAgent>() : new ArrayList<IAgent>( scope.getTopology().getNeighborsOf(scope, centralAg, distance, filter)); double sizeNorm = FastMath.sqrt(centralAg.getEnvelope().getArea()); Map<IAgent, Double> distancesCoeff = new TOrderedHashMap<IAgent, Double>(); distancesCoeff.put(centralAg, 1.0); for (IAgent ag : neighbors) { double euclidDist = centralAg.getLocation().euclidianDistanceTo(ag.getLocation()); double dist = 1 / (1.0 + euclidDist / sizeNorm); distancesCoeff.put(ag, dist); } for (int i = 0; i < nbCat; i++) { for (int j = 0; j < nbCat; j++) { for (int k = 0; k < nbCat; k++) { List<Integer> ca = new ArrayList(); ca.add(i); ca.add(j); ca.add(k); double xa = 0; double xs = 0; for (IAgent ag : distancesCoeff.keySet()) { double dist = distancesCoeff.get(ag); double xatmp = fuzzyTransition(scope, fuzzytransitions, nbCat, i, k, i, j) * dist; double xstmp = fuzzyTransition(scope, fuzzytransitions, nbCat, i, j, i, k) * dist; if (xatmp > xa) { xa = xatmp; } if (xstmp > xs) { xs = xstmp; } } if (xa > 0) { Map<Double, Double> mapxa = XaPerTransition.get(ca); if (mapxa == null) { mapxa = new TOrderedHashMap<Double, Double>(); mapxa.put(xa, 1.0); XaPerTransition.put(ca, mapxa); } else { if (mapxa.containsKey(xa)) { mapxa.put(xa, mapxa.get(xa) + 1.0); } else { mapxa.put(xa, 1.0); } } Xvals.add(xa); } if (xs > 0) { Map<Double, Double> mapxs = XsPerTransition.get(ca); if (mapxs == null) { mapxs = new TOrderedHashMap<Double, Double>(); mapxs.put(xs, 1.0); XsPerTransition.put(ca, mapxs); } else { if (mapxs.containsKey(xa)) { mapxs.put(xs, mapxs.get(xs) + 1.0); } else { mapxs.put(xs, 1.0); } } Xvals.add(xs); } } } } } }