Hi!

I would like to write a conflict resolution strategy that orders (all) activations into a completely random order. I've written a simple class implementing the Strategy interface, looks like this:

public final class RandomActivation implements Strategy, Serializable
{
    private static final long serialVersionUID = 1L;
    private static final String mName = "RandomActivation";
    private final Random mGenerator;

    public RandomActivation()
    {
        mGenerator = new Random();
    }

public final int compare( final Activation pAct1, final Activation pAct2 )
    {
        int result;

        final double r1 = mGenerator.nextDouble();
        final double r2 = mGenerator.nextDouble();

        if ( r1 < r2 )
        {
            result = 1;
        }
        else if ( r1 > r2 )
        {
            result = -1;
        }
        else
        {
            result = 0;
        }
        return result;
    }

    public final String getName()
    {
        return mName;
    }
}

(I don't know whether the random numbers are really necessary, as I've read in a former message that returning 0 would result an indeterministic order of the activations, anyway my problem has nothing to do with this.)
I've noticed that this strategy doesn't behave as I have expected.
I watched how many times the compare method was invoked after a new activation was placed to the agenda,
and I don't understand why there are such activations
that aren't compared to every other activations. Isn't this the way the conflict resolution should work?
Compare every activations to every others?
For example there was such activation that was compared to only one other activation... Why is that?
Or am I misunderstanding something? Please explain me how and how many times
the compare method should be invoked, and how can I reach a complete random reordering of the agenda.
Thanks.


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
in the BODY of a message to [email protected], NOT to the list
(use your own address!) List problems? Notify [email protected].
--------------------------------------------------------------------

Reply via email to