public static Task buildBehaviorTask( Scheduler scheduler, SparseArrayProgramDistribution sparseArrayProgramDistribution, AdvancedAdaptiveLevinSearchProgramDatabase database, AdvancedAdaptiveLevinSearchProblem problem ) { // used by all tasks to inform other tasks (and the same task) that a search was successful, so all other tasks abort their search too Observable completitionObservable = new Observable(); /* * * start direct search * * start at max 3 searches which use the already present functions, searches go up to programlength = 4 (inclusive ret) */ uint maximalParallelSearchesForIndirectPrograms = 3; Parallel parallel = new Parallel(); parallel.maxCounterFailure = maximalParallelSearchesForIndirectPrograms; parallel.maxCounterSuccess = 1; // we just need one successful // query for related already solved problem with programs which solve it var databaseEntriesWithProgramsOfSimilarProblems = database.getQuery() .whereHumanReadableHintsAny(problem.humanReadableHints) .enumerable; Random random = new Random(); // fill tasks throw new NotImplementedException("TODO"); /* TODO * foreach ( var iterationDatabaseEntry in databaseEntriesWithProgramsOfSimilarProblems * .OrderBy(v => random.Next()) // randomize order * .Take((int)maximalParallelSearchesForIndirectPrograms) * ) { * // derive a problem with the parentProgram * AdvancedAdaptiveLevinSearchProblem derivedProblem = * problem * .shallowCopy() * .setEnumerationMaxProgramLength(TODO) * .setParentProgram(iterationDatabaseEntry.program); * * SearchTask createdSearchTask = new SearchTask( * scheduler, * sparseArrayProgramDistribution, * derivedProblem, * completitionObservable * ); * parallel.children.Add(createdSearchTask); * } */ return(parallel); }
// public void initiateSearch(SparseArrayProgramDistribution programDistribution, uint enumerationMaxProgramLength) { searchIterations = 0; this.programDistribution = programDistribution; this.enumerationMaxProgramLength = enumerationMaxProgramLength; privateNumberOfInstructions = 1 + /* with RET*/ 1; numberOfInstructionsToEnumerate = 6; // we enumerate at maximum with just 6 instructions programSampler = new ProgramSampler(programDistribution, numberOfInstructionsToEnumerate, instructionsetCount); programSampler.setInstructionsetCount(instructionsetCount); int programInitialSize = 512; localInterpreterState.program = new MutableArray <uint>(programInitialSize); reinintateSearch(); }
void testALS() { prepare(); //joinIrc1(); var absolute = PathHelper.AssemblyDirectory.Uri.AbsoluteUri; var absoluteWithoutFile = absolute.Substring(8); var pathParts = new List <string>(absoluteWithoutFile.Split(new char[] { '/' })); var pathPartsWithoutSpecific = pathParts; for (;;) { string lastPathPart = pathPartsWithoutSpecific[pathPartsWithoutSpecific.Count - 1]; if (lastPathPart == "bin") { break; } pathPartsWithoutSpecific.RemoveAt(pathPartsWithoutSpecific.Count - 1); } pathPartsWithoutSpecific.RemoveAt(pathPartsWithoutSpecific.Count - 1); pathPartsWithoutSpecific.RemoveAt(pathPartsWithoutSpecific.Count - 1); pathPartsWithoutSpecific.AddRange(new string[] { "MetaNixCore", "functionalSrc", "problems" }); string directoryPath = string.Join("\\", pathPartsWithoutSpecific.ToArray()); string[] problemsFilenames = Directory.GetFiles(directoryPath); PatternSymbolContext patternSymbolContext = new PatternSymbolContext(); patternSymbolContext.lookupOrCreateSymbolIdAndUniqueIdForName("null"); // must have 0 as uniqueId patternSymbolContext.lookupOrCreateSymbolIdAndUniqueIdForName("true"); // must have 1 as uniqueId patternSymbolContext.lookupOrCreateSymbolIdAndUniqueIdForName("false"); // must have 2 as uniqueId Scheduler scheduler = new Scheduler(); AdvancedAdaptiveLevinSearchProgramDatabase levinSearchProblemDatabase = new AdvancedAdaptiveLevinSearchProgramDatabase(); SparseArrayProgramDistribution sparseArrayProgramDistribution = new SparseArrayProgramDistribution(); AdvancedAdaptiveLevinSearchTaskProvider levinSearchTaskProvider = new AdvancedAdaptiveLevinSearchTaskProvider(scheduler, sparseArrayProgramDistribution, levinSearchProblemDatabase, logger); // overwrite for testing problemsFilenames = new string[] { @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\Induction_array_verticalAddition.txt", @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\level1\Induction_array_integer_exists.txt", /* * * * @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\Induction_linkedlist_next.txt", * @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\Induction_linkedlist_append.txt", * @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\Induction_array_appendBeginningAndEnding.txt", * @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\Induction_array_removeEqual.txt", * @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\Induction_array_subReg0.txt", * @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\Induction_array_multiplication.txt", * @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\induction_array_binaryNegation.txt", * @"C:\Users\r0b3\github\AGI-X0\code\c#\MetaNixCore\functionalSrc\problems\Induction_array_negation.txt", */ }; foreach (string iterationPath in problemsFilenames) { string fileContent = File.ReadAllText(iterationPath); Lexer lexer = new Lexer(); lexer.setSource(fileContent); Functional2LexerAndParser parser = new Functional2LexerAndParser(patternSymbolContext); parser.lexer = lexer; parser.parse(); Pattern <Decoration> problemRootElement = parser.rootPattern; MetaNix.framework.pattern.Interpreter.vmAssert(problemRootElement.isBranch, false, "Must be branch!"); MetaNix.framework.pattern.Interpreter.vmAssert(problemRootElement.decoration == null, false, "Must be pure branch!"); Pattern <Decoration> configurationPattern = problemRootElement.referenced[0]; AdvancedAdaptiveLevinSearchProblem levinSearchProblem = new AdvancedAdaptiveLevinSearchProblem(); var iterationPathParts = new List <string>(iterationPath.Split(new char[] { '\\' })); string taskname = iterationPathParts[iterationPathParts.Count - 1].Substring(0, iterationPathParts[iterationPathParts.Count - 1].Length - 4); levinSearchProblem.humanReadableTaskname = taskname; //levinSearchProblem.enumerationMaxProgramLength = 5; levinSearchProblem.instructionsetCount = InstructionInfo.getNumberOfInstructions() - 16; /*because no call*/ levinSearchProblem.maxNumberOfRetiredInstructions = Conversion.convertToUint(configurationPattern.referenced[1]); // TODO< derive by propability with some formula from schmidhuber > // read hints for indirect call candidates Pattern <Decoration> hintIndirectCallCandidatesPattern = configurationPattern.referenced[2]; foreach (var iHintPattern in hintIndirectCallCandidatesPattern.referenced) { string iHint = Conversion.convertPatternToString(iHintPattern); levinSearchProblem.humanReadableIndirectlyCallableProgramNames.Add(iHint); } //levinSearchProblem.localInitialInterpreterState = new LocalInterpreterState(); //levinSearchProblem.localInitialInterpreterState.registers = new int[3]; //levinSearchProblem.initialInterpreterState.debugExecution = false; levinSearchProblem.enumerationMaxProgramLength = Conversion.convertToUint(configurationPattern.referenced[0]); for (int trainingSampleI = 1; trainingSampleI < problemRootElement.referenced.Length; trainingSampleI++) { var trainingSamplePattern = problemRootElement.referenced[trainingSampleI]; MetaNix.framework.pattern.Interpreter.vmAssert(trainingSamplePattern.isBranch, false, "Must be branch!"); MetaNix.framework.pattern.Interpreter.vmAssert(trainingSamplePattern.decoration == null, false, "Must be pure branch!"); Pattern <Decoration> questionArrayPattern = trainingSamplePattern.referenced[0], questionRegistersPattern = trainingSamplePattern.referenced[1], answerArrayPattern = trainingSamplePattern.referenced[3], answerRegistersPattern = trainingSamplePattern.referenced[4]; // append TrainingSample createdTrainingSample = new TrainingSample(); createdTrainingSample.questionArray = new List <int>(Conversion.convertToIntArray(questionArrayPattern)); createdTrainingSample.questionRegisters = Conversion.convertToOptionalIntArray(questionRegistersPattern); createdTrainingSample.questionArrayIndex = Conversion.convertToOptionalInt(trainingSamplePattern.referenced[2]); createdTrainingSample.answerRegisters = Conversion.convertToOptionalIntArray(answerRegistersPattern); createdTrainingSample.answerArray = new List <int>(Conversion.convertToIntArray(answerArrayPattern)); createdTrainingSample.answerArrayIndex = Conversion.convertToOptionalInt(trainingSamplePattern.referenced[5]); levinSearchProblem.trainingSamples.Add(createdTrainingSample); } levinSearchTaskProvider.problems.Add(levinSearchProblem); } levinSearchTaskProvider.submitFirstTask(); for (; ;) { scheduler.process(); } }