I have different scenarios in my model, and in each scenario some road segments (edges) of the road network (Graph) is degraded (loses capacity) or disrupted (removed because of total damage). For that reason, I am trying to iterate over a set of edges for each scenario, starting with the original network, and update the network by changing capacity of some of the edges and removing some others. In the beginning I did not use an iterator to iterate over the edges which resulted in "ConcurrentModificationException". Then I changed the code so as to use Iterator, but this time it does not allow me to use remove method with my iterator (edgeIt.remove()). How can I solve this issue? Thanks for your help in advance.
.....
ArrayList<FloydWarshallShortestPaths<Integer, DefaultWeightedEdge>> FWS = new ArrayList<FloydWarshallShortestPaths<Integer, DefaultWeightedEdge>>();
for(int w=0; w<numOfScenarios; w++){
FWS.add(w, fr.readData(fileName));
}
....
//Road Network and Shelters after disruption in Scenarios
for(int i=1; i<6; i++){
Iterator<FloydWarshallShortestPaths<Integer, DefaultWeightedEdge>> it = FWS.iterator();
while(it.hasNext()){
FloydWarshallShortestPaths<Integer, DefaultWeightedEdge> FWIt = it.next();
Iterator<DefaultWeightedEdge> edgeIt = FWIt.getGraph().edgeSet().iterator();
while(edgeIt.hasNext()){
DefaultWeightedEdge e = edgeIt.next();
if(arcRiskZoneIndex[FWIt.getGraph().getEdgeSource(e)][FWIt.getGraph().getEdgeTarget(e)][FWS.indexOf(FWIt)]==i){
if(rng.nextDouble()<=arcDisruptProb[FWS.indexOf(FWIt)][i-1]){
roadCapS[FWS.get(FWS.indexOf(FWIt)).getGraph().getEdgeSource(e)][FWS.get(FWS.indexOf(FWIt)).getGraph().getEdgeTarget(e)][FWS.indexOf(FWIt)]=(roadCap[FWIt.getGraph().getEdgeSource(e)][FWIt.getGraph().getEdgeTarget(e)]*10000-rng.nextInt(((int) (10000*roadCap[FWIt.getGraph().getEdgeSource(e)][FWIt.getGraph().getEdgeTarget(e)]/2000))+1)*2000)/10000;
if(roadCapS[FWIt.getGraph().getEdgeSource(e)][FWIt.getGraph().getEdgeTarget(e)][FWS.indexOf(FWIt)]==0.0){
**edgeIt.remove()**;
}
}
}
}
for(int s:setOfFacilityNodesDummy){
if(shelterRiskZoneIndex[s][FWS.indexOf(FWIt)]==i){
if(rng.nextDouble()<=shelterDisruptProb[FWS.indexOf(FWIt)][i-1]){
setOfFacilityNodesS.get(FWS.indexOf(FWIt)).remove(s);
}
}
}
}
}