Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/15 13:28:37 (9 years ago)
Author:
abeham
Message:

#2174:

  • Some refactorings and bug fixes
  • Renamed (Binary|Integer|Real)Encoding to (Binary|Integer|Real)VectorEncoding
  • Improved error messages when compiling programmable problems
Location:
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/ProblemDefinitionScript.cs

    r11880 r11885  
    7171      var assembly = base.Compile();
    7272      var types = assembly.GetTypes();
     73      if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
     74        throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition.");
     75      if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
     76        throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed.");
     77
     78      CompiledProblemDefinition inst;
    7379      try {
    74         var inst = (CompiledProblemDefinition)Activator.CreateInstance(types.First(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
     80        inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
     81      } catch (Exception e) {
     82        compiledProblemDefinition = null;
     83        throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e);
     84      }
     85
     86      try {
    7587        inst.vars = new Variables(VariableStore);
    7688        inst.Initialize();
     89      } catch (Exception e) {
     90        compiledProblemDefinition = null;
     91        throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e);
     92      }
     93
     94      try {
    7795        CompiledProblemDefinition = inst;
    7896      } catch (Exception e) {
    7997        compiledProblemDefinition = null;
    80         throw;
     98        throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e);
    8199      }
     100
    82101      return assembly;
    83102    }
Note: See TracChangeset for help on using the changeset viewer.