24 package org.lightvoting.simulation.rule;
29 import cern.colt.bitvector.BitVector;
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.LinkedHashMap;
34 import java.util.LinkedList;
35 import java.util.List;
37 import java.util.Map.Entry;
68 public BitVector
applyRuleBV(
final List<String> p_alternatives,
final List<BitVector> p_votes,
final int p_comSize )
75 final int[] l_valuesVect =
new int[m_alternatives.size()];
77 Map<Integer, Integer> l_valuesMap =
new HashMap<Integer, Integer>();
78 for (
int i = 0; i < m_alternatives.size(); i++ )
80 for (
int j = 0; j < m_bitVotes.size(); j++ )
90 l_valuesMap.put( i, l_valuesVect[i] );
95 l_valuesMap = this.sortMapDESC( l_valuesMap );
101 for (
final Entry<Integer, Integer> l_entry : l_valuesMap.entrySet() )
105 m_comBV.put( l_entry.getKey(),
true );
121 public Map<Integer, Integer>
sortMapDESC(
final Map<Integer, Integer> p_valuesMap )
123 final List<Entry<Integer, Integer>> l_list =
new LinkedList<>( p_valuesMap.entrySet() );
126 Collections.sort( l_list, ( p_first, p_second ) ->
127 p_second.getValue().compareTo( p_first.getValue() ) );
130 final Map<Integer, Integer> l_sortedMap =
new LinkedHashMap<Integer, Integer>();
131 for (
final Entry<Integer, Integer> l_entry : l_list )
133 l_sortedMap.put( l_entry.getKey(), l_entry.getValue() );
Created by sophie on 10.01.17.
List< BitVector > m_bitVotes
BitVector applyRuleBV(final List< String > p_alternatives, final List< BitVector > p_votes, final int p_comSize)
compute the winning committee according to Minisum Approval
Map< Integer, Integer > sortMapDESC(final Map< Integer, Integer > p_valuesMap)
sort HashMap according to its values in descending order
List< String > m_alternatives