As a part of my program I stuck to Concurrent Modification Exception. Here is the mentioned part:
PriorityQueue<Customer> marginalGainHeap = new PriorityQueue<Customer>(
1, new Comparator<Customer>() {
public int compare(Customer c1, Customer c2) {
return Double.compare(c1.getMarginalGain(),
c2.getMarginalGain());
}
});
// set of all remains available nodes
availableNodes.removeAll(churnNet);
for (Customer avail : availableNodes) {
avail.setMarginalGain(0);
marginalGainHeap.add(avail);
}
while (seedSet.size() <= budget) {
**for (Customer remainingNode : availableNodes) {**
remainingNode.setMarginalGain(calculateMarginalGain(
remainingNode, seedSet, network, availableNodes,
churnNet));
marginalGainHeap.remove(remainingNode);
marginalGainHeap.add(remainingNode);
}
seedSet.add(marginalGainHeap.poll());
}
Here is the calculateMarginalGain Method:
private int calculateMarginalGain(Customer remainingNode,
HashSet<Customer> seedSet,
DirectedSparseGraph<Customer, Transaction> net,
Set<Customer> availableNodes, HashSet<Customer> churnNetwork) {
// Marginal gain for short-term campaign
HashSet<Customer> tmp = new HashSet<Customer>(); // seedset U
// {remainingNode}
tmp.add(remainingNode);
Set<Customer> tmpAvailableNodes = availableNodes;
HashSet<Customer> NeighborOfChurn = getNeighbors(churnNetwork, net);
// sigma function for calculating the expected number of influenced
// customers- seedSettmp=seedset U {u}
tmpAvailableNodes.removeAll(NeighborOfChurn);
Set<Customer> influencedNet = getNeighbors(tmp, net);
tmpAvailableNodes.retainAll(influencedNet);
return tmpAvailableNodes.size();
}
I got this exception on the line of program that I specify with **. I find out that this error could be caused by Iterator. But I did not use any one! Please help me find out what caused that exception and how can I fix that?
Regards.