コード例 #1
0
ファイル: CartCentering.cs プロジェクト: lulzzz/BraneCloud
        public override float EvaluateTestCase(GAIndividual inIndividual, object inInput, object inOutput)
        {
            int        timeSteps       = 1000;
            float      timeDiscritized = 0.01f;
            float      maxTime         = timeSteps * timeDiscritized;
            float      captureRadius   = 0.01f;
            ObjectPair xv       = (ObjectPair)inInput;
            float      position = (float)xv._first;
            float      velocity = (float)xv._second;

            for (int step = 1; step <= timeSteps; step++)
            {
                _interpreter.ClearStacks();
                FloatStack   fStack = _interpreter.FloatStack();
                BooleanStack bStack = _interpreter.BoolStack();
                ObjectStack  iStack = _interpreter.InputStack();
                // Position will be on the top of the stack, and velocity will be
                // second.
                fStack.Push(position);
                fStack.Push(velocity);
                // Must be included in order to use the input stack. Uses same order
                // as inputs on Float stack.
                iStack.Push(position);
                iStack.Push(velocity);
                _interpreter.Execute(((PushGPIndividual)inIndividual)._program, _executionLimit);
                // If there is no boolean on the stack, the program has failed to
                // return a reasonable output. So, return a penalty fitness of
                // twice the maximum time.
                if (bStack.Size() == 0)
                {
                    return(2 * maxTime);
                }
                // If there is a boolean, use it to compute the next position and
                // velocity. Then, check for termination conditions.
                // NOTE: If result == True, we will apply the force in the positive
                // direction, and if result == False, we will apply the force in
                // the negative direction.
                bool  positiveForce = bStack.Top();
                float acceleration;
                if (positiveForce)
                {
                    acceleration = 0.5f;
                }
                else
                {
                    acceleration = -0.5f;
                }
                velocity = velocity + (timeDiscritized * acceleration);
                position = position + (timeDiscritized * velocity);
                // Check for termination conditions
                if (position <= captureRadius && position >= -captureRadius && velocity <= captureRadius && velocity >= -captureRadius)
                {
                    //Cart is centered, so return time it took.
                    return(step * timeDiscritized);
                }
            }
            // If here, the cart failed to come to rest in the allotted time. So,
            // return the failed error of maxTime.
            return(maxTime);
        }
コード例 #2
0
ファイル: Instructions.cs プロジェクト: lulzzz/BraneCloud
        // End code iteration functions
        //
        // Conversion instructions to code
        //
        public override void Execute(Interpreter inI)
        {
            ObjectStack  codeStack = inI.CodeStack();
            BooleanStack bStack    = inI.BoolStack();

            if (bStack.Size() > 0)
            {
                codeStack.Push(bStack.Pop());
            }
        }
コード例 #3
0
        protected void setUp()
        {
            interpreter = new Interpreter();
            Program instructionList = new Program("( )");

            interpreter.randProgram.SetInstructions(interpreter, instructionList);
            istack = new IntStack();
            fstack = new FloatStack();
            bstack = new BooleanStack();
        }
コード例 #4
0
ファイル: Instructions.cs プロジェクト: lulzzz/BraneCloud
        public override void Execute(Interpreter inI)
        {
            BooleanStack bstack = inI.BoolStack();

            if (_stack.Size() > 1)
            {
                object o1 = _stack.Pop();
                object o2 = _stack.Pop();
                bstack.Push(o1.Equals(o2));
            }
        }
コード例 #5
0
ファイル: Instructions.cs プロジェクト: lulzzz/BraneCloud
        public override void Execute(Interpreter inI)
        {
            BooleanStack bstack = inI.BoolStack();
            ObjectStack  estack = inI.ExecStack();

            if (_stack.Size() > 1 && bstack.Size() > 0)
            {
                bool   istrue  = bstack.Pop();
                object iftrue  = _stack.Pop();
                object iffalse = _stack.Pop();
                if (istrue)
                {
                    estack.Push(iftrue);
                }
                else
                {
                    estack.Push(iffalse);
                }
            }
        }
コード例 #6
0
        public void PushInput(Interpreter inI, int n)
        {
            ObjectStack _stack = inI.InputStack();

            if (_stack.Size() > n)
            {
                object inObject = _stack.DeepPeek(n);
                if (inObject is int)
                {
                    IntStack istack = inI.IntStack();
                    istack.Push((int)inObject);
                }
                else
                {
                    // if (inObject is Number)
                    // {
                    //   FloatStack fstack = inI.FloatStack();
                    //   fstack.Push(((Number)inObject).FloatValue());
                    // }
                    //else
                    if (inObject is float)
                    {
                        FloatStack fstack = inI.FloatStack();
                        fstack.Push((float)inObject);
                    }
                    else
                    {
                        if (inObject is bool)
                        {
                            BooleanStack bstack = inI.BoolStack();
                            bstack.Push((bool)inObject);
                        }
                        else
                        {
                            Console.Error.WriteLine("Error during input.index - object " + inObject.GetType() +
                                                    " is not a legal object according to " + this.GetType() + ".");
                        }
                    }
                }
            }
        }
コード例 #7
0
        public override void Execute(Interpreter inI)
        {
            BooleanStack stack = inI.BoolStack();

            stack.Push(_stack.Size() > 0);
        }