public void SolveHalfTime(DataSet data, int iterations)
            {
                //define constants

                this.data  = data;
                this.param = new Microsoft.SolverFoundation.Solvers.NelderMeadSolverParams();
                int[] constants;
                //Solver
                solver = new Microsoft.SolverFoundation.Solvers.NelderMeadSolver();

                // Objective function.
                int objId;

                solver.AddRow("obj", out objId);
                solver.AddGoal(objId, 0, true);

                // Define variables.
                constants = new int[1];
                for (int i = 0; i < data.Variables.Count; i++)
                {
                    if (data.Variables[i].ConstName == "T1/2")
                    {
                        solver.AddVariable(data.Variables[i].ConstName, out constants[0]);
                        solver.SetLowerBound(constants[0], data.XVals[0]);
                        solver.SetUpperBound(constants[0], data.XVals[data.XVals.Length - 1]);
                        solver.SetValue(constants[0], 0);
                        break;
                    }
                }

                // Assign objective function delegate.
                solver.FunctionEvaluator = FunctionValueHalfTime;

                // Solve.
                param.IterationLimit = iterations;

                var solution = solver.Solve(param);

                for (int i = 0; i < data.Variables.Count; i++)
                {
                    if (data.Variables[i].ConstName == "T1/2")
                    {
                        data.Variables[i].ConstValue = solution.GetValue(constants[0]);
                        break;
                    }
                }
            }
Beispiel #2
0
        public double SolveHalfTime(Expression e, int iterations, double start, double stop, double half, double value)
        {
            try
            {
                this.e    = e;
                this.half = half;
                //define constants
                this.param = new Microsoft.SolverFoundation.Solvers.NelderMeadSolverParams();
                int[] constants;
                //Solver
                solver = new Microsoft.SolverFoundation.Solvers.NelderMeadSolver();

                // Objective function.
                int objId;
                solver.AddRow("obj", out objId);
                solver.AddGoal(objId, 0, true);

                // Define variables.
                constants = new int[1];

                solver.AddVariable("t", out constants[0]);
                solver.SetLowerBound(constants[0], start);
                solver.SetUpperBound(constants[0], stop);
                solver.SetValue(constants[0], value);

                // Assign objective function delegate.
                solver.FunctionEvaluator = FunctionValueHalfTime;

                // Solve.
                param.IterationLimit = iterations;

                var solution = solver.Solve(param);

                return(solution.GetValue(constants[0]));
            }
            catch
            {
                return(value);
            }
        }