logist.task
Class TaskSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<Task>
          extended by logist.task.TaskSet
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<Task>, java.util.Collection<Task>, java.util.Set<Task>

public abstract class TaskSet
extends java.util.AbstractSet<Task>
implements java.lang.Cloneable

A specialized Set implementation for use with Task objects. All elements in a TaskSet must come from the same task batch that is generated before each simulation round. TaskSet are represented internally as bit vectors.

The iterator returned by the iteratormethod traverses the elements in order of increasing task id.

Note that TaskSets or Tasks from different round are not compatible and cannot be combined.

The implementation of this class is based on Joshua Bloch's EnumSet from the Java Collections Framework.

Author:
Robin Steiger, (largely based on EnumSet implementation by Josh Bloch)

Method Summary
 TaskSet clone()
          Returns a copy of this set.
static TaskSet copyOf(TaskSet s)
          Creates a new task set containing the same elements as the specified task set.
static TaskSet create(Task[] universe)
          For system use only.
static TaskSet intersect(TaskSet s1, TaskSet s2)
          Creates a new task set containing the intersection of two task sets.
static TaskSet intersectComplement(TaskSet s1, TaskSet s2)
          Creates a new task set containing the intersection of a task set with the complement of another task set.
abstract  java.util.Iterator<Task> iterator()
          Returns an iterator over the elements contained in this set.
static TaskSet noneOf(TaskSet s)
          Creates an empty task set ranging over the same universe as the specified task set.
 int rewardSum()
          Sums the rewards of all tasks.
 java.lang.String toString()
           
static TaskSet union(TaskSet s1, TaskSet s2)
          Creates a new task set containing the union of two task sets.
 int weightSum()
          Sums the weights of all tasks.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, retainAll, size, toArray, toArray
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, isEmpty, remove, retainAll, size, toArray, toArray
 

Method Detail

create

public static TaskSet create(Task[] universe)
For system use only.
Creates a new task set for a given task batch. The returned set contains all tasks.

Parameters:
universe -
Throws:
java.lang.IllegalArgumentException - if some task id does not match with the index in the table

copyOf

public static TaskSet copyOf(TaskSet s)
Creates a new task set containing the same elements as the specified task set.

Parameters:
s - the collection from which to initialize this task set

noneOf

public static TaskSet noneOf(TaskSet s)
Creates an empty task set ranging over the same universe as the specified task set.

Parameters:
s - the collection from which to initialize this task set

union

public static TaskSet union(TaskSet s1,
                            TaskSet s2)
Creates a new task set containing the union of two task sets.

Parameters:
s1 -
s2 -
Returns:
the set of elements contained by either s1 or s2
Throws:
java.lang.IllegalArgumentException - if s1 and s2 are task sets from different rounds

intersect

public static TaskSet intersect(TaskSet s1,
                                TaskSet s2)
Creates a new task set containing the intersection of two task sets.

Parameters:
s1 -
s2 -
Returns:
the set of elements contained by both s1 and s2
Throws:
java.lang.IllegalArgumentException - if s1 and s2 are task sets from different rounds

intersectComplement

public static TaskSet intersectComplement(TaskSet s1,
                                          TaskSet s2)
Creates a new task set containing the intersection of a task set with the complement of another task set. The complement is taken with respect to all tasks in the universe (i.e. in the current round).

Parameters:
s1 -
s2 -
Returns:
the set of elements contained by s1, but not by s2
Throws:
java.lang.IllegalArgumentException - if s1 and s2 are task sets from different rounds

weightSum

public int weightSum()
Sums the weights of all tasks.

Returns:
The sum of weights of all tasks in the set.

rewardSum

public int rewardSum()
Sums the rewards of all tasks.

Returns:
The sum of rewards of all tasks in the set.

iterator

public abstract java.util.Iterator<Task> iterator()
Returns an iterator over the elements contained in this set. The iterator traverses the elements in the order of increasing task ids.

Specified by:
iterator in interface java.lang.Iterable<Task>
Specified by:
iterator in interface java.util.Collection<Task>
Specified by:
iterator in interface java.util.Set<Task>
Specified by:
iterator in class java.util.AbstractCollection<Task>
Returns:
an iterator over the elements contained in this set

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection<Task>

clone

public TaskSet clone()
Returns a copy of this set.

Overrides:
clone in class java.lang.Object
Returns:
a copy of this set.