protected void placeSheeps() { sheeps = new ArrayList<>(par.numSheeps); double range = par.arenaSize / par.numSheeps; for (int i = 0; i < par.numSheeps; i++) { Sheep sheep = new Sheep(this, field); Double2D newLoc = null; if (par.randomSheepPosition) { newLoc = new Double2D( par.sheepX * par.arenaSize, i * range + sheep.getRadius() + random.nextDouble() * (range - sheep.getRadius() * 2)); } else { newLoc = new Double2D(par.sheepX * par.arenaSize, i * range + range / 2); } if (par.sheepPositionOffset > 0) { Double2D deviation = new Double2D( (random.nextDouble() * 2 - 1) * par.sheepPositionOffset, (random.nextDouble() * 2 - 1) * par.sheepPositionOffset); newLoc = newLoc.add(deviation); } sheep.setLocation(newLoc); sheep.setStopper(schedule.scheduleRepeating(sheep)); sheeps.add(sheep); } activeSheeps = new ArrayList<>(sheeps); }
private void frameAnalysis(ArrayList<SimInfo> sia) { if (!(timeStamp > startTime && timeStamp <= endTime)) return; frameNum++; int size = sia.size(); speedLost += history.size() - size; thetaLost += history.size() - size; if (size == 0) return; while (size > history.size()) { history.add(new ArrayList<SimInfo>()); speedLost += frameNum - 1; thetaLost += frameNum - 1; } SimInfo si = null; SimInfo si2 = null; double xOff, yOff, thetaOff; double speed; ArrayList<MutableDouble2D> pa = new ArrayList<MutableDouble2D>(); MutableDouble2D loc = null; for (int i = 0; i < size; i++) { loc = new MutableDouble2D(sia.get(i).getPX(), sia.get(i).getPY()); pa.add(loc); si = sia.get(i); si2 = getRecorded(sia_recorder, si); if (si2 != null && si != null) { // in the sia_recorder xOff = si.getPX() - si2.getPX(); yOff = si.getPY() - si2.getPY(); speed = Math.sqrt(xOff * xOff + yOff * yOff) / (si.getTimeStamp() - si2.getTimeStamp()); if (speed < minSpeed) minSpeed = speed; if (speed > maxSpeed) maxSpeed = speed; thetaOff = Math.atan2(si.getDY(), si.getDX()) - Math.atan2(si2.getDY(), si2.getDX()); if (thetaOff > Math.PI) thetaOff -= 2 * Math.PI; if (thetaOff < -Math.PI) thetaOff += 2 * Math.PI; if (Math.abs(thetaOff) > maxThetaOff) maxThetaOff = thetaOff; if (Math.abs(thetaOff) < minThetaOff) minThetaOff = Math.abs(thetaOff); int speedIndex = (int) (speed / speedWidth); int thetaIndex = (int) (Math.abs(thetaOff) / 0.01); if (speed == 0) speedZero++; if (speedIndex >= (int) (guessedMaxSpeed / speedWidth)) speedOutBound++; if (speedIndex < (int) (guessedMaxSpeed / speedWidth) && speed > 0) speedHistogram[speedIndex]++; if (thetaOff == 0) thetaZero++; if (thetaIndex >= (int) (Math.PI / thetaWidth)) thetaOutBound++; if (thetaIndex < (int) (Math.PI / thetaWidth) && Math.abs(thetaOff) > 0) thetaHistogram[thetaIndex]++; if (speed > 0.12) { System.out.println("ts1: " + si2.getTimeStamp() + " id: " + si2.getId()); System.out.println("ts2: " + si.getTimeStamp() + " id: " + si.getId()); } } else { speedLost++; thetaLost++; } } double tmp; ArrayList<Integer> ia = new ArrayList<Integer>(); // store the id of the // interacting agent ArrayList<Integer> ib = new ArrayList<Integer>(); // store the agentType // of the // interacting agent Interaction interaction = null; ArrayList<Interaction> interactionList = new ArrayList<Interaction>(); for (int i = 0; i < size; i++) { si = sia.get(i); ia.clear(); ib.clear(); interactionList.clear(); boolean in_touch = false; for (int j = 0; j < size; j++) { if (j != i) { tmp = Math.pow(pa.get(i).getX() - pa.get(j).getX(), 2); tmp += Math.pow(pa.get(i).getY() - pa.get(j).getY(), 2); tmp = Math.sqrt(tmp); if (tmp <= interacting_distance) { // interacting in_touch = true; ia.add(sia.get(j).getId()); ib.add(sia.get(j).getAgentType()); } } } int interacting_index = find_id(interacting, si.getId()); if (in_touch) { if (interacting_index != -1) { if ((Math.abs(interacting.get(interacting_index).getPX() - si.getPX()) < 0.0000002) && (Math.abs(interacting.get(interacting_index).getPY() - si.getPY()) < 0.0000002)) { if (si.getTimeStamp() - interacting.get(interacting_index).getTimeStamp() >= interacting_time_length) { interacting.get(interacting_index).setTimeStamp(si.getTimeStamp()); interacting.get(interacting_index).setPX(si.getPX()); interacting.get(interacting_index).setPY(si.getPY()); interacting_count++; } } else { interacting.get(interacting_index).setTimeStamp(si.getTimeStamp()); interacting.get(interacting_index).setPX(si.getPX()); interacting.get(interacting_index).setPY(si.getPY()); } } else { interacting.add(si); } } else { if (interacting_index != -1) { interacting.get(interacting_index).setTimeStamp(si.getTimeStamp()); interacting.get(interacting_index).setPX(si.getPX()); interacting.get(interacting_index).setPY(si.getPY()); } else { interacting.add(si); } } try { writer.write( " <row> 1:" + si.getTimeStamp() + " 2:" + si.getAgentType() + " 3:" + si.getId() + " 4:" + si.getPX() + " 5:" + si.getPY() + " 6:" + si.getPZ() + " 7:" + si.getDX() + " 8:" + si.getDY() + " 9:" + si.getDZ() + " 10:["); for (int k = 0; k < ia.size(); k++) { int type = getInteractionType(sia, ib.get(k), ia.get(k), si.getAgentType(), si.getId()); Double2D toLoc = getToLocation(sia, ib.get(k), ia.get(k), si.getAgentType(), si.getId()); if (type != -1) { interaction = new Interaction(type, toLoc.getX(), toLoc.getY()); interactionList.add(interaction); writer.write( "(" + interaction.getType() + ":" + ia.get(k) + "{" + interaction.getToX() + "+" + interaction.getToY() + "})"); } } writer.write("] </row>\n"); writer.flush(); si.setInteractionList(interactionList); while (history.size() <= si.getId()) { history.add(new ArrayList<SimInfo>()); speedLost += frameNum - 1; thetaLost += frameNum - 1; } history.get(si.getId()).add(si); } catch (IOException e) { System.err.println(e); System.exit(1); } } sia_recorder.clear(); for (int i = 0; i < sia.size(); i++) { sia_recorder.add(sia.get(i)); } }