@Override
    public OccurrenceAllocation select(SolverState schedule, Occurrence forOccurrence) {
        // Allocations aligned to elementary intervals start and ends
        AlignedOccurrenceAllocationsIterator allocations = 
                new AlignedOccurrenceAllocationsIterator(forOccurrence, schedule.allocationsMultimap());
    
        // cost function
        //MinDurationConflictAllocationCost cost = 
        //        new MinDurationConflictAllocationCost(forOccurrence, schedule);
        
        // save allocations to list
        ArrayList<AllocationAndCost> allocationsList = new ArrayList<>();
        
        while(allocations.hasNext()) {
            BaseInterval<Integer> allocation = allocations.next();
            if (allocation.equals(forOccurrence.getAllocation().toInterval())) {
                continue;
            }
            
            long allocationCost = forOccurrence.getPreferrenceCost(allocation);
            
            allocationsList.add(new AllocationAndCost(allocation, 1d/(allocationCost+1)));
        }
        
        // compute sum
        double valueSum = 0;
        for (int i = 0; i < allocationsList.size(); i++) {
            valueSum += allocationsList.get(i).cost;
        }
        
        // select 
        double selection = random.nextDouble() * valueSum;
        
        // retrieve selected
        valueSum = 0;
        for (int i = 0; i < allocationsList.size(); i++) {
            valueSum += allocationsList.get(i).cost;
            if (valueSum > selection) {
                
                return new OccurrenceAllocation(allocationsList.get(i).allocation);
            }
        }
        
        throw new IllegalStateException();
    }