internal CostFunction compileCostFunction(AllSections sections) { var func = compileFunction(prepareFunctionCode(sections, sections.CostFunctionSection.Function)); testFunction(func.Item1, sections.DimensionSection.Dim); return(new CostFunction(func.Item1, func.Item2)); }
private string prepareFunctionCode(AllSections sections, string funcCode) { string code = string.Format("(System.Func<Vector, double>)( (x) => {0} )", funcCode); if (sections.ParametersSection != null) { code = string.Format("{0}\n{1}", sections.ParametersSection.Content, code); } return(code); }
public Task Parse(string input) { AllSections sections = SectionsParser.ParseSections(input); return(new Task ( (int)sections.DimensionSection.Dim, compileCostFunction(sections), compileConstraints(sections), input )); }
internal List <Constraint> compileConstraints(AllSections sections) { if (sections.ConstraintsSection != null) { return(sections.ConstraintsSection.Constraints.Select((s) => { var func = compileFunction(prepareFunctionCode(sections, s.LhsOnlyVersion)); testFunction(func.Item1, sections.DimensionSection.Dim); return new Constraint(func.Item1, s.Type, func.Item2); }).ToList()); } else { return(new List <Constraint>()); } }
public static AllSections ParseSections(string c) { string input = InputPreprocesor.ReplaceNumberedVaraiblesWithIndexedOnes(c); List <Section> sections = Split(input); EnforceSectionsAreUnique(sections); foreach (var s in sections) { s.Parse(); } try { AllSections result = new AllSections() { DimensionSection = sections.SingleOrDefault((s) => s.GetType() == typeof(DimensionSection)) as DimensionSection, ParametersSection = sections.SingleOrDefault((s) => s.GetType() == typeof(ParametersSection)) as ParametersSection, CostFunctionSection = sections.Single((s) => s.GetType() == typeof(CostFunctionSection)) as CostFunctionSection, ConstraintsSection = sections.SingleOrDefault((s) => s.GetType() == typeof(ConstraintsSection)) as ConstraintsSection }; if (result.DimensionSection == null) { uint dim = InputPreprocesor.FindDimension(input); result.DimensionSection = new DimensionSection() { Dim = dim, Content = dim.ToString() + ";" }; } return(result); } catch (InvalidOperationException) { throw new ArgumentException("Nie znaleziono wymaganej sekcji: '$fuction'"); } }