public bool SetObjectiveFunction(string objectiveFunctionString) { if (ObjectiveFunction.TryParse(objectiveFunctionString, out ObjectiveFunction objectiveFunction)) { ObjectiveFunction = objectiveFunction; } else { return(false); } return(true); }
public static bool TryParse(string objectiveFunctionString, out ObjectiveFunction objectiveFunction) { objectiveFunction = new ObjectiveFunction(); if (string.IsNullOrWhiteSpace(objectiveFunctionString)) { return(false); } string coefficientText = ""; bool negitive = false; char previousChar = ' '; foreach (char character in objectiveFunctionString) { if (character == ' ') { continue; } else if (character == '+') { negitive = false; } else if (character == '-') { negitive = true; } if (character == '.' || char.IsDigit(character)) { coefficientText += character; } else if (char.IsLetter(character) && !char.IsLetter(previousChar)) { if (string.IsNullOrWhiteSpace(coefficientText)) { coefficientText = "1"; } if (double.TryParse(coefficientText, out double coefficient)) { objectiveFunction.AddVariable(character, coefficient * (negitive ? -1 : 1)); } coefficientText = ""; } else if (char.IsLetter(character) && char.IsLetter(previousChar)) { return(false); } previousChar = character; } return(true); }
public MainWindow() { InitializeComponent(); ObjectiveFunction instance = new ObjectiveFunction(); instance.ShowDialog(); objFunction = instance.ObjFunction; objFunction_label.Content = "Your objective function: \n" + objFunction; addConstraint_btn.Click += AddConstraint_btn_Click; deleteConstraint_btn.Click += DeleteConstraint_btn_Click; solve_btn.Click += Solve_btn_Click; }
public void Output() { System.Console.Write("Maximize \t"); ObjectiveFunction.Output(); System.Console.Write("Subject to \t"); if (Constraints.Length > 0) { Constraints[0].Output(); for (int i = 1; i < Constraints.Length; i++) { System.Console.Write("\t\t"); Constraints[i].Output(); } } }
public LPParser() { ObjectiveFunction = new ObjectiveFunction(); Constraints = new List <Constraint>(); }
public LinearProgram() { ObjectiveFunction = new ObjectiveFunction(); Constraints = new Constraint[0]; }