static public LP FromFile(string fileName) { StreamReader sr = new StreamReader(fileName); LP lp = new LP(false); int nvars = Int32.Parse(sr.ReadLine()); double[] costs = new double[nvars]; string[] cw = sr.ReadLine().Split(new char[] { ' ' }); for (int i = 0; i < nvars; i++) { costs[i] = Double.Parse(cw[i]); } lp.InitCosts(costs); sr.ReadLine();//swallow the line "constraints" int nConstraints = Int32.Parse(sr.ReadLine()); for (int i = 0; i < nConstraints; i++) { string constr = sr.ReadLine(); string[] words = constr.Split(new char[] { ' ' }); List <string> ws = new List <string>(); foreach (string s in words) { if (s != "") { ws.Add(s); } } double[] coeff = new double[nvars]; for (int j = 0; j < nvars; j++) { coeff[j] = Double.Parse((string)ws[j]); } Relation rel = (string)ws[nvars] == "=" ? Relation.Equal : (string)ws[nvars] == "<=" ? Relation.LessOrEqual : Relation.GreaterOrEqual; double rs = Double.Parse((string)ws[nvars + 1]); lp.AddConstraint(coeff, rel, rs); sr.ReadLine(); //eat the empty line } sr.Close(); return(lp); }
public void InitCosts(double[] costsParam) { lp.InitCosts(costsParam); rsm.InitCosts(costsParam); }
static public LP FromFile(string fileName) { StreamReader sr = new StreamReader(fileName); LP lp = new LP(false); int nvars = Int32.Parse(sr.ReadLine()); double[] costs = new double[nvars]; string[] cw = sr.ReadLine().Split(new char[] { ' ' }); for (int i = 0; i < nvars; i++) costs[i] = Double.Parse(cw[i]); lp.InitCosts(costs); sr.ReadLine();//swallow the line "constraints" int nConstraints = Int32.Parse(sr.ReadLine()); for (int i = 0; i < nConstraints; i++) { string constr = sr.ReadLine(); string[] words = constr.Split(new char[] { ' ' }); List<string> ws = new List<string>(); foreach (string s in words) { if (s != "") ws.Add(s); } double[] coeff = new double[nvars]; for (int j = 0; j < nvars; j++) { coeff[j] = Double.Parse((string)ws[j]); } Relation rel = (string)ws[nvars] == "=" ? Relation.Equal : (string)ws[nvars] == "<=" ? Relation.LessOrEqual : Relation.GreaterOrEqual; double rs = Double.Parse((string)ws[nvars + 1]); lp.AddConstraint(coeff, rel, rs); sr.ReadLine(); //eat the empty line } sr.Close(); return lp; }