Пример #1
0
    protected Solution iteration(LevinProblem problem, out bool done)
    {
        done = false;

        if (currentIteration > maxIterations)
        {
            done = true;
            return(null);
        }

        List <LevinProgram> currentLevinPrograms = new List <LevinProgram>();

        if (currentIteration == 0)
        {
            // we have to seed the current levin programs
            for (uint instructionI = 0; instructionI < numberOfInstructions; instructionI++)
            {
                LevinProgram program = new LevinProgram();
                program.instructions = new List <uint> {
                    instructionI
                };

                currentLevinPrograms.Add(program);
            }
        }
        else
        {
            // form new programs we haven't jet executed
            for (uint instructionI = 0; instructionI < numberOfInstructions; instructionI++)
            {
                currentLevinPrograms.AddRange(concatInstructionBeforePreviousLevinPrograms(instructionI));
            }
        }



        // TODO< order programs by propability ? >


        // execute programs
        foreach (LevinProgram iterationProgram in currentLevinPrograms)
        {
            uint maxNumberOfStepsToExecute = (uint)((calcSolomonoffLevinMeasure(iterationProgram) * (double)phase) / c);

            bool hasHalted;
            executeProgram(iterationProgram, problem, maxNumberOfStepsToExecute, out hasHalted);
            if (hasHalted)
            {
                done = true;
                return(new Solution(iterationProgram));
            }
        }


        previousLevinPrograms = currentLevinPrograms;
        phase *= 2;
        currentIteration++;

        return(null);
    }
Пример #2
0
    public Solution iterate(LevinProblem problem, uint numberOfIterations, out bool done)
    {
        done = false;

        for (uint i = 0; i < numberOfIterations; i++)
        {
            Solution solution = iteration(problem, out done);
            if (done)
            {
                return(solution);
            }
        }

        return(null);
    }
Пример #3
0
 private void executeProgram(LevinProgram program, LevinProblem problem, uint maxNumberOfStepsToExecute, out bool hasHalted)
 {
     problem.executeProgram(program, maxNumberOfStepsToExecute, out hasHalted);
 }