RePast
v. 2.0

uchicago.src.sim.util
Class SimUtilities

java.lang.Object
  |
  +--uchicago.src.sim.util.SimUtilities

public class SimUtilities
extends Object

Static Utility methods for RePast simulations.


Method Summary
static double[] getPointFromHeadingAndDistance(int heading, int distance)
          Gets an x, y coordinate as a double[] of length 2, given a heading (0-359) and a distance.
static void logException(String msg, Exception ex)
          Logs the specified message and exception to ./repast.log.
static int norm(int val, int size)
          Normalize the specified value to the specified size
static void showError(String msg, Exception ex)
          Displays an error message on the screen and prints the message and the exception message and stack trace to a ./repast_error.log
static void showMessage(String msg)
          Displays a message in a dialog box.
static void shuffle(double[] array, cern.jet.random.Uniform rng)
          Shuffles the specified double[] using the specifid Uniform rng.
static void shuffle(List list)
          Shuffles the specified list using Random.uniform.
static void shuffle(List list, cern.jet.random.Uniform rng)
          Shuffles the specified list using the specifid Uniform rng.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

shuffle

public static void shuffle(List list)
Shuffles the specified list using Random.uniform. This list is shuffled by iterating backwards through the list and swapping the current item with a randomly chosen item. This randomly chosen item will occur before the current item in the list.

Parameters:
list - the list to shuffle
See Also:
Random

shuffle

public static void shuffle(List list,
                           cern.jet.random.Uniform rng)
Shuffles the specified list using the specifid Uniform rng. This list is shuffled by iterating backwards through the list and swapping the current item with a randomly chosen item. This randomly chosen item will occur before the current item in the list.

Parameters:
list - the List to shuffle
rng - the random number generator to use for the shuffle

shuffle

public static void shuffle(double[] array,
                           cern.jet.random.Uniform rng)
Shuffles the specified double[] using the specifid Uniform rng. This list is shuffled by iterating backwards through the list and swapping the current item with a randomly chosen item. This randomly chosen item will occur before the current item in the list.

Parameters:
array - the double[] to shuffle
rng - the random number generator to use for the shuffle

getPointFromHeadingAndDistance

public static double[] getPointFromHeadingAndDistance(int heading,
                                                      int distance)
Gets an x, y coordinate as a double[] of length 2, given a heading (0-359) and a distance. The point of origin is 0, 0 and the returned coordinate is relative to this distance. (An agent can calculate a new coordinate by adding the returned coordinates to its own x, y values.) This assumes that north = 0 degrees, east = 90 and so on.

Parameters:
heading - the heading in degrees
distance - the distance to travel along the heading
Returns:
a double[] with the calculated coordinate

norm

public static int norm(int val,
                       int size)
Normalize the specified value to the specified size

Parameters:
val - the value to normalize
size - the size to normalize the value to
Returns:
the normalized value

showMessage

public static void showMessage(String msg)
Displays a message in a dialog box.


showError

public static void showError(String msg,
                             Exception ex)
Displays an error message on the screen and prints the message and the exception message and stack trace to a ./repast_error.log


logException

public static void logException(String msg,
                                Exception ex)
Logs the specified message and exception to ./repast.log.

Parameters:
msg - the message to log
ex - the exception to log

RePast
v. 2.0

Bug reports and feature requests to RePast