Пример #1
0
        public string CopyTextWithSubstitutions(string text, string fileName, IReplacement replacement)
        {
            string destPath = Path.Combine(OutputDirectory, fileName);

            File.WriteAllText(destPath, replacement.Apply(text));
            return(destPath);
        }
Пример #2
0
 public MigrationStrategy(IRandom random, ISelection selection, IReplacement reinsertion, ParameterSet parameters) : base(random, selection, reinsertion, parameters)
 {
     Random      = random;
     Selection   = selection;
     Reinsertion = reinsertion;
     Parameters  = parameters;
 }
Пример #3
0
 protected MigrationStrategyBase(IRandom random, ISelection selection, IReplacement reinsertion, ParameterSet parameters)
 {
     Random      = random;
     Selection   = selection;
     Reinsertion = reinsertion;
     Parameters  = parameters;
 }
Пример #4
0
 private Configuration(int n, int k, double a, double b,
                       ISelection method1,
                       ISelection method2,
                       ISelection method3,
                       ISelection method4,
                       ICrossover crossover,
                       IMutation mutation,
                       double mutationProbability,
                       IReplacement replacement,
                       IFinisher finisher,
                       Character.Type characterType)
 {
     this.N                  = n;
     this.K                  = k;
     this.A                  = a;
     this.B                  = b;
     this.Method1            = method1;
     this.Method2            = method2;
     this.Method3            = method3;
     this.Method4            = method4;
     this.CrossoverMethod    = crossover;
     this.MutationMethod     = mutation;
     this.ReplacementMethod  = replacement;
     this.MutationProbablity = mutationProbability;
     this.FinishCondition    = finisher;
     this.CharacterType      = characterType;
 }
Пример #5
0
        public string CopyFileWithSubstitutions(string fileName, IReplacement replacement, string destFileName = null)
        {
            string srcPath  = Path.Combine(SourceDirectory, fileName);
            string destPath = Path.Combine(OutputDirectory, destFileName ?? fileName);

            string text = replacement.Apply(File.ReadAllText(srcPath));

            File.WriteAllText(destPath, text);
            return(destPath);
        }
Пример #6
0
        public void TestReadRunCommand()
        {
            IEnumerable <IReplacement> replacements = new IReplacement[]
            {
                new PropertyReplacement("path", "value"),
                new ModelReplacement("x", new MockModel())
            };
            ICommand target = new RunCommand(true, true, 32, replacements, new[] { "sim1, sim2" });

            TestRead(target);
        }
Пример #7
0
        public void TestWriteRunCommand()
        {
            IEnumerable <IReplacement> replacements = new IReplacement[]
            {
                new ModelReplacement("f", new MockModel()),
                new PropertyReplacement("path to a model", "replacement value")
            };
            IEnumerable <string> sims    = new[] { "one simulation" };
            ICommand             command = new RunCommand(false, true, 65536, replacements, sims);

            TestWrite(command);
        }
Пример #8
0
        private static Configuration LoadConfiguration(ConfigurationFile configFile)
        {
            ISelection method1       = GetSelection(configFile.Method1, configFile),
                       method2       = GetSelection(configFile.Method2, configFile),
                       method3       = GetSelection(configFile.Method3, configFile),
                       method4       = GetSelection(configFile.Method4, configFile);
            ICrossover   crossover   = GetCrossover(configFile.CrossoverMethod);
            IMutation    mutation    = GetMutation(configFile.MutationMethod);
            IReplacement replacement = GetReplacement(configFile.ReplacementMethod, configFile.N, configFile.K);

            Character.Type type     = GetCharacterType(configFile.CharacterType);
            IFinisher      finisher = GetFinisher(configFile.Finish, configFile);

            if (configFile.HeightMutationDelta.HasValue)
            {
                HeightGene.Delta = configFile.HeightMutationDelta.Value;
            }
            return(new Configuration(configFile.N, configFile.K, configFile.A, configFile.B, method1, method2, method3, method4,
                                     crossover, mutation, configFile.MutationProbability, replacement, finisher, type));
        }
Пример #9
0
        public override Verb CreateVerb(string[] tokens)
        {
            var parsers = new List <Parser>
            {
                new StringElementParser(),
                new FieldScanElementParser(),
                new ListElementParser(),
                new BalanceElementParser(),
                new LengthElementParser(),
                new FieldDelimiterElementParser(),
                new TabElementParser(),
                new RemElementParser(),
                new WordBoundaryElementParser(),
                new StringBoundaryElementParser(),
                new AtElementParser(),
                new AssertElementParser(),
                new BreakXElementParser(),
                new SpanElementParser(),
                new ArbNoElementParser(),
                new ArbElementParser(),
                new ClassElementParser(),
                new AlternateElementParser(),
                new OptionalElementParser(),
                new RangeElementParser(),
                new CountElementParser(),
                new PatternParser(true, true),
                new AnyElementParser(),
                new BlockElementParser(),
                new SingleCharacterElementParser(),
                new HexElementParser(),
                new FunctionElementParser(),
                new ConstantElementParser(),
                new VariableElementParser(),
                new EndPatternParser(IgnoreReplacement)
            };

            var index = position + length;

            Color(position, length, Structures);

            Element head           = null;
            Element currentElement = null;

            var          scanning          = true;
            var          sourceLength      = source.Length;
            var          isAlternate       = false;
            var          isOptional        = false;
            IReplacement replacement       = null;
            var          not               = false;
            var          conditionalParser = new ConditionalParser();
            var          replacementParser = new ReplacementParser();
            var          found             = false;

            while (scanning && index < sourceLength)
            {
                scanning = false;
                found    = false;
                foreach (var parser in parsers.Where(parser => parser.Scan(source, index)))
                {
                    if (parser is EndPatternParser endPatternParser)
                    {
                        replacement = endPatternParser.Replacement;
                        index       = endPatternParser.Result.Position;
                        found       = true;
                        break;
                    }

                    if (parser is AlternateElementParser)
                    {
                        isAlternate = true;
                        index       = parser.Result.Position;
                        scanning    = true;
                        found       = true;
                        break;
                    }

                    if (parser is OptionalElementParser)
                    {
                        isOptional = true;
                        index      = parser.Result.Position;
                        scanning   = true;
                        found      = true;
                        break;
                    }

                    if (!(parser is IElementParser elementParser))
                    {
                        continue;
                    }

                    var element = elementParser.Element;

                    if (not)
                    {
                        element.Not = true;
                        not         = false;
                    }

                    if (element is NegateElement)
                    {
                        not      = true;
                        index    = parser.Result.Position;
                        scanning = true;
                        found    = true;
                        break;
                    }

                    element.ID = CompilerState.ObjectID();
                    index      = parser.Result.Position;

                    if (replacementParser.Scan(source, index))
                    {
                        element.Replacement = replacementParser.Replacement;
                        index = replacementParser.Result.Position;
                    }

                    if (conditionalParser.Scan(source, index))
                    {
                        index = conditionalParser.Result.Position;
                    }
                    element.Conditional = conditionalParser.Conditional;

                    if (isOptional)
                    {
                        element.Alternate = new StringElement("");
                        isOptional        = false;
                    }

                    if (element.AutoOptional)
                    {
                        element.Alternate = new StringElement("");
                    }

                    if (isAlternate)
                    {
                        currentElement.AppendAlternate(element);
                        isAlternate = false;
                    }
                    else
                    {
                        if (head == null)
                        {
                            head = element;
                        }
                        else
                        {
                            currentElement.AppendNext(element);
                        }
                        currentElement = element;
                    }
                    scanning = true;
                    found    = true;
                    break;
                }
            }

            Assert(found, "Pattern parser", $"Didn't understand pattern '{source.Substring(index)}'");

            if (head == null)
            {
                head = new FailElement();
            }

            var newPattern = new Pattern(head)
            {
                Replacement = replacement,
                LastElement = currentElement,
                SubPattern  = subPattern
            };

            overridePosition  = index;
            newPattern.Source = source.Substring(position, index - position).Trim();
            if (resultElement)
            {
                Element = new PatternElement(newPattern);
                return(new NullOp());
            }

            result.Value = newPattern;
            return(new Push(newPattern));
        }
Пример #10
0
 /// <summary>
 /// Add an override to replace an existing model, as specified by the
 /// path, with a replacement model.
 /// </summary>
 /// <param name="replacement">An instance of a replacement that needs to be applied when simulation is run.</param>
 public void AddOverride(IReplacement replacement)
 {
     replacementsToApply.Add(replacement);
 }
Пример #11
0
 public ReplacementViewModel(IReplacement replacement)
 {
     Replacement = replacement;
 }
Пример #12
0
 public ReplacementLiteral(IReplacement replacement) => this.replacement = replacement;