Пример #1
0
    public static void printNeighbors(ArrayList neighbors) {
        int i = 0;
        for(Neighbor neighbor : neighbors) {
            Instance instance = neighbor.getInstance();

            System.out.println("\nNeighbor " + (i + 1) + ", distance: " + neighbor.getDistance());
            i++;
            for(Feature f : instance.getAttributes()) {
                System.out.print(f.getName() + ": ");
                if(f instanceof Category) {
                    System.out.println(((Category)f).getCategory().toString());
                }
                else if(f instanceof Distance) {
                    System.out.println(((Distance)f).getDistance().toString());
                }
                else if (f instanceof Expiration) {
                    System.out.println(((Expiration)f).getExpiry().toString());
                }
                else if (f instanceof Handset) {
                    System.out.print(((Handset)f).getOs().toString() + ", ");
                    System.out.println(((Handset)f).getDevice().toString());
                }
                else if (f instanceof Offer) {
                    System.out.println(((Offer)f).getOfferType().toString());
                }
                else if (f instanceof WSAction) {
                    System.out.println(((WSAction)f).getAction().toString());
                }
            }
        }
    }
Пример #2
0
 void insert(Neighbor node) {
   Neighbor prev = null, next = list;
   double distance = node.distance;
   while (next != null && next.distance < distance) {
     prev = next;
     next = prev.next;
   }
   node.next = next;
   if (prev == null) {
     list = node;
   } else {
     prev.next = node;
   }
 }
Пример #3
0
    public static WSAction.Action determineMajority(ArrayList neighbors) {
        int yea = 0, ney = 0;

        for(int i = 0; i &lt; neighbors.size(); i++) { 			Neighbor neighbor = neighbors.get(i); 			Instance instance = neighbor.getInstance(); 			if(instance.isRedeemed()) { 				yea++; 			} 			else { 				ney++; 			} 		} 		 		if(yea &gt; ney) {
            return WSAction.Action.Redeem;
        }
        else {