private void CalculateMultiReturn() { double mult = 2 * Math.PI / 800; double r, g, b; int index = 0; // Assign the parser variables ParserVariable x = new ParserVariable(0); ParserVariable y = new ParserVariable(0); muParser.Parser p = new muParser.Parser(muParser.Parser.EBaseType.tpDOUBLE); p.DefineOprt("%", new Parser.Fun2Delegate(mod), 2); p.SetExpr(m_parserImg[0].GetExpr() + "," + m_parserImg[1].GetExpr() + "," + m_parserImg[2].GetExpr()); p.DefineVar("x", x); p.DefineVar("y", y); for (int yi = 0; yi < pbImage.Height; ++yi) { y.Value = (yi - 400) * mult; for (int xi = 0; xi < pbImage.Width; ++xi) { x.Value = (xi - 400) * mult; int nNum; double[] ret = p.EvalMultiExpr(); r = GetColorComponent(ret[0]); g = GetColorComponent(ret[1]); b = GetColorComponent(ret[2]); m_data[index] = (byte)(r * 255); m_data[index + 1] = (byte)(g * 255); m_data[index + 2] = (byte)(b * 255); index += 3; } } }
private void CalculateMultiThread(object s) { CalcState cs = s as CalcState; double mult = 2 * Math.PI / 800; int index = 0; // Set up parser variables Parser p = cs.Parser; ParserVariable x = new ParserVariable(0); ParserVariable y = new ParserVariable(0); p.DefineVar("x", x); p.DefineVar("y", y); // Do the actual looping for a single colorplane double v; for (int yi = 0; yi < pbImage.Height; ++yi) { y.Value = (yi - 400) * mult; for (int xi = 0; xi < pbImage.Width; ++xi) { x.Value = (xi - 400) * mult; v = GetColorComponent(p.Eval()); m_data[index + cs.Offset] = (byte)(v * 255); index += 3; } } cs.Reset.Set(); }
public DeliveryOptimizer(string expr, double tMax, int n, double cSt, double cDl) { this.tMax = tMax; this.n = n; this.cSt = cSt; this.cDl = cDl; prs = new Parser(); pvT = new ParserVariable(); prs.DefineVar("t", pvT); prs.SetExpr(expr); int nGrid = 100; double tStep = tMax / nGrid; pvT.Value = 0; double f0 = prs.Eval(); arrTFunc = new double[nGrid + 1]; arrVFunc = new double[nGrid + 1]; for (int i = 0; i < nGrid + 1; i++) { arrTFunc[i] = i * tStep; pvT.Value = arrTFunc[i]; arrVFunc[i] = prs.Eval() - f0; } }
private void CalculateMultiThread(object s) { CalcState cs = s as CalcState; float mult = 2 * (float)Math.PI / (float)256.0; int index = 0; // Set up parser variables Parser p = cs.Parser; ParserVariable x = new ParserVariable(0); ParserVariable y = new ParserVariable(0); p.DefineVar("x", x); p.DefineVar("y", y); Parser.CompiledFunDelegate fun = p.Compile(); // Do the actual looping for a single colorplane float v; for (int yi = 0; yi < pbImage.Height; ++yi) { y.Value = (yi - 128) * mult; for (int xi = 0; xi < pbImage.Width; ++xi) { x.Value = (xi - 128) * mult; //v = GetColorComponent(p.Eval()); v = GetColorComponent(fun()); m_data[index + cs.Offset] = (byte)(v * 255); index += 3; } } cs.Reset.Set(); }
public static Sample Transform(Sample[] arrS, string expr) { Sample st = new Sample(); Parser prs = new Parser(); prs.SetExpr(expr); ParserVariable[] arrV = new ParserVariable[arrS.Length]; for (int i = 0; i < arrS.Length; i++) { arrV[i] = new ParserVariable(); prs.DefineVar(arrS[i].id, arrV[i]); } double[] arrT = new double[arrS[0].arr.Length]; for (int i = 0; i < arrT.Length; i++) { for (int j = 0; j < arrV.Length; j++) { arrV[j].Value = arrS[j].arr[i]; } arrT[i] = prs.Eval(); } for (int i = 0; i < arrT.Length; i++) { if (double.IsInfinity(arrT[i]) || double.IsNaN(arrT[i])) { throw new Exception(); } } st.arr = arrT; st.idHtml = st.id = expr; st.name = expr; st.Calculate(); return(st); }
public HJInitialParams(double xEpsilon, double fEpsilon, string[] arrName, string[] arrHtmlName, string expression) { this.xEpsilon = xEpsilon; this.fEpsilon = fEpsilon; this.arrName = arrName; this.arrHtmlName = arrHtmlName; prs = new Parser(); arrVar = new ParserVariable[arrName.Length]; for (int i = 0; i < arrName.Length; i++) { arrVar[i] = new ParserVariable(0); prs.DefineVar(arrName[i], arrVar[i]); } prs.SetExpr(expression); }
public NMInitialParams(double alpha, double beta, double gamma, double epsilon, string[] arrName, string[] arrHtmlName, string expression) { this.alpha = alpha; this.beta = beta; this.gamma = gamma; this.epsilon = epsilon; this.arrName = arrName; this.arrHtmlName = arrHtmlName; prs = new Parser(); arrVar = new ParserVariable[arrName.Length]; for (int i = 0; i < arrName.Length; i++) { arrVar[i] = new ParserVariable(0); prs.DefineVar(arrName[i], arrVar[i]); } prs.SetExpr(expression); }
public DeliveryOptimizer(string expr, double tMax, int n) { this.tMax = tMax; this.n = n; Parser prs = new Parser(); ParserVariable pvX = new ParserVariable(); prs.DefineVar("x", pvX); prs.SetExpr(expr); double tStep = tMax / n; arrW = new double[n]; for (int i = 0; i < arrW.Length; i++) { pvX.Value = tStep * i; double f1 = prs.Eval(); pvX.Value = tStep * (i + 1); double f2 = prs.Eval(); arrW[i] = (f2 - f1) / tStep; } }
private void CalculateSingleThread() { float mult = 2 * (float)Math.PI / (float)256.0; float r, g, b; int index = 0; //// Assign the parser variables ParserVariable x = new ParserVariable(0); ParserVariable y = new ParserVariable(0); foreach (muParser.Parser p in m_parserImg) { p.DefineVar("x", x); p.DefineVar("y", y); } //Parser.CompiledFunDelegate funRed = m_parserImg[(int)EColorPlane.red].Compile(); //Parser.CompiledFunDelegate funGreen = m_parserImg[(int)EColorPlane.green].Compile(); //Parser.CompiledFunDelegate funBlue = m_parserImg[(int)EColorPlane.blue].Compile(); int h = pbImage.Height; int w = pbImage.Width; for (int yi = 0; yi < h; ++yi) { y.Value = (yi - 128) * mult; for (int xi = 0; xi < w; ++xi) { x.Value = (xi - 128) * mult; r = GetColorComponent(m_parserImg[(int)EColorPlane.red].Eval()); g = GetColorComponent(m_parserImg[(int)EColorPlane.green].Eval()); b = GetColorComponent(m_parserImg[(int)EColorPlane.blue].Eval()); m_data[index] = (byte)(r * 255); m_data[index + 1] = (byte)(g * 255); m_data[index + 2] = (byte)(b * 255); index += 3; } } }
private void CalculateSingleThread() { double mult = 2 * Math.PI / 800; double r, g, b; int index = 0; // Assign the parser variables ParserVariable x = new ParserVariable(0); ParserVariable y = new ParserVariable(0); foreach (muParser.Parser p in m_parserImg) { p.DefineVar("x", x); p.DefineVar("y", y); } for (int yi = 0; yi < pbImage.Height; ++yi) { y.Value = (yi - 400) * mult; for (int xi = 0; xi < pbImage.Width; ++xi) { x.Value = (xi - 400) * mult; r = m_parserImg[(int)EColorPlane.red].Eval(); g = m_parserImg[(int)EColorPlane.green].Eval(); b = m_parserImg[(int)EColorPlane.blue].Eval(); r = GetColorComponent(r); g = GetColorComponent(g); b = GetColorComponent(b); m_data[index] = (byte)(r * 255); m_data[index + 1] = (byte)(g * 255); m_data[index + 2] = (byte)(b * 255); index += 3; } } }
static public double[,] GenerateData(int smpCount, int n, string exprM, string exprS) { double[,] data = new double[smpCount, n]; Parser prsM = new Parser(), prsS = new Parser(); prsM.SetExpr(exprM); prsS.SetExpr(exprS); ParserVariable varT = new ParserVariable(); prsM.DefineVar("t", varT); prsS.DefineVar("t", varT); NormalDistribution dist = new NormalDistribution(); for (int i = 0; i < smpCount; i++) { varT.Value = i + 1; dist.SetDistributionParameters(prsM.Eval(), prsS.Eval()); for (int j = 0; j < n; j++) { data[i, j] = dist.NextDouble(); } } return(data); }
static void Main(string[] args) { Parser parser = new Parser(); MainLogic.Pathes pathes = new MainLogic.Pathes(); var area = MainLogic.Owner.Instance; { var p0 = Primitive.Create(); MainLogic.IPrimitive p1 = null; for (int i = 0; i < 10; i++) { var p = Primitive.Create(); if (i % 1 == 0) { MainLogic.Link.Create(p1 ?? p0, p); } p1 = p; } MainLogic.Link.Create(p0, p1); pathes.Generete(p0); Console.WriteLine(MainLogic.Owner.Instance.Links.Count().ToString()); Console.WriteLine(MainLogic.Owner.Instance.Primitives.Count().ToString()); foreach (var l in MainLogic.Owner.Instance.Links) { Console.WriteLine(l.ToString()); } Console.WriteLine(pathes.ToString()); } object o = new object(); object o1 = new object(); try { // System.CodeDom.Compiler.CodeParser parser = new System.CodeDom.Compiler.CodeParse; int n1 = 5, n2 = 10; var date = DateTime.Now; parser.SetExpr("5"); Console.WriteLine(parser.Eval()); Console.WriteLine(DateTime.Now - date); date = DateTime.Now; //Thread.Sleep(1000); var r1 = new ParserVariable(5); r1.Value = 10; parser.DefineVar("x1", r1); //parser.DefineVar("x1", new ParserVariable(1)); r1.Value = 4; parser.SetExpr("x1 = 5"); Console.WriteLine(parser.Eval()); Console.WriteLine(r1.Value); Console.WriteLine(DateTime.Now - date); date = DateTime.Now; parser.SetExpr("5<1"); Console.WriteLine(parser.Eval()); Console.WriteLine(DateTime.Now - date); date = DateTime.Now; parser.SetExpr("5+1"); Console.WriteLine(parser.Eval()); Console.WriteLine(DateTime.Now - date); date = DateTime.Now; //parser.SetExpr("5+1"); Console.WriteLine((1 + 5).ToString()); Console.WriteLine(DateTime.Now - date); Console.WriteLine((o.GetHashCode()).ToString()); Console.WriteLine(MainLogic.BaseObjectTypes.Reply.GetHashCode()); } catch (ParserException ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }