예제 #1
0
        private void printSolution(ILinearSolution s)
        {
            Console.WriteLine("LpResult {0}", s.LpResult);
            Console.WriteLine("MipResult {0}", s.MipResult);
            Console.WriteLine("Result {0}", s.Result);
            Console.WriteLine("SolutionQuality {0}", s.SolutionQuality);
            Console.WriteLine("SolvedGoalCount {0}", s.SolvedGoalCount);

            foreach (int vid in VariableIndices)
            {
                Console.WriteLine("basis {0}", s.GetBasic(vid));
            }
            foreach (int vid in RowIndices)
            {
                Console.WriteLine("basis {0}", s.GetBasic(vid));
            }

            Console.WriteLine("GetSolutionValue {0}", (double)s.GetSolutionValue(1));

            foreach (int vid in VariableIndices)
            {
                Console.WriteLine("value {0}", (double)s.GetValue(vid));
            }
            foreach (int vid in RowIndices)
            {
                Console.WriteLine("value {0}", (double)s.GetValue(vid));
            }

            Object key;
            int    avid;
            bool   fMinimize;
            bool   fOptimal;

            s.GetSolvedGoal(0, out key, out avid, out fMinimize, out fOptimal);
        }
예제 #2
0
 public override double[] Solve(IAssembly assembly, ILinearSolution linearScheme, double[] forceVector)
 {
     discretization = assembly;
     linearSolver   = linearScheme;
     lambda         = 1.0 / numberOfLoadSteps;
     double[] solution = StartNewtonIterations(forceVector);
     return(solution);
 }
예제 #3
0
        public override double[] Solve(IAssembly assembly, ILinearSolution linearScheme, double[] forceVector)
        {
            InternalForces      = new Dictionary <int, double[]>();
            Solutions           = new Dictionary <int, double[]>();
            LoadStepConvergence = new List <string>();
            if (localSolutionVector == null)
            {
                localSolutionVector = new double[forceVector.Length];
            }
            discretization = assembly;
            linearSolver   = linearScheme;
            lambda         = 1.0 / numberOfLoadSteps;
            //double[] solution = null;

            //Thread tcore1 = new Thread(() => LoadControlledNR(forceVector));
            //tcore1.Start();
            //tcore1.Join();
            double[] solution = LoadControlledNR(forceVector);
            return(solution);
        }
예제 #4
0
 public CentralDifferences(ILinearSolution linearSolver, InitialConditions initialValues, double totalTime, int timeStepsNumber, double[,] stiffnessMatrix, double[,] massMatrix, double[] externalForcesVector)
 {
     totalDOFs                 = stiffnessMatrix.GetLength(0);
     this.totalTime            = totalTime;
     this.timeStepsNumber      = timeStepsNumber;
     timeStep                  = totalTime / timeStepsNumber;
     this.massMatrix           = massMatrix;
     this.stiffnessMatrix      = stiffnessMatrix;
     dampingMatrix             = new double[totalDOFs, totalDOFs];
     this.externalForcesVector = externalForcesVector;
     initialDisplacementVector = initialValues.InitialDisplacementVector;
     initialVelocityVector     = initialValues.InitialVelocityVector;
     initialAccelerationVector = initialValues.InitialAccelerationVector;
     initialTime               = initialValues.InitialTime;
     this.linearSolver         = linearSolver;
     a0 = 1.0 / (timeStep * timeStep);
     a1 = 1.0 / (2.0 * timeStep);
     a2 = 2.0 * a0;
     a3 = 1.0 / a2;
 }
예제 #5
0
 public virtual double[] Solve(IAssembly assembly, ILinearSolution linearScheme, double[] forceVector)
 {
     throw new Exception("LinearSolution.Solve not implemented");
 }
예제 #6
0
        protected static void CCN_Simplex()
        {
            int param1 = ReadSelectionInt("Max agents", 100, min: 1, max: 1000);
            var param3 = ReadSelectionInt("Max time\"", 120, min: 10, max: 1200);

            //Set agent shifts
            var      solveShifts = new CSP.ShiftsPlanner(param1);
            TimeSpan ts8h        = GetTimeSpanHours(8);
            TimeSpan ts9h        = GetTimeSpanHours(9);
            TimeSpan ts10h       = GetTimeSpanHours(10);
            TimeSpan ts30mi      = GetTimeSpanMinutes(30);

            var shifts = new List <CSP.Models.Shift>();

            shifts.Add(new CSP.Models.Shift(name: "A", start: GetTimeSpanHours(7), duration: ts8h));
            shifts.Add(new CSP.Models.Shift(name: "G", start: GetTimeSpanHours(8), duration: ts8h));
            shifts.Add(new CSP.Models.Shift(name: "B", start: GetTimeSpanHours(9), duration: ts8h));
            shifts.Add(new CSP.Models.Shift(name: "I", start: GetTimeSpanHours(10), duration: ts8h));
            shifts.Add(new CSP.Models.Shift(name: "E", start: GetTimeSpanHours(11), duration: ts8h));
            shifts.Add(new CSP.Models.Shift(name: "D", start: GetTimeSpanHours(13), duration: ts8h));
            shifts.Add(new CSP.Models.Shift(name: "C", start: GetTimeSpanHours(15), duration: ts8h));
            shifts.Add(new CSP.Models.Shift(name: "CL", start: GetTimeSpanHours(16), duration: ts8h));
            shifts.Add(new CSP.Models.Shift(name: "H", start: GetTimeSpanHours(17), duration: ts8h));

            shifts.Add(new CSP.Models.Shift(name: "A++", start: GetTimeSpanHours(7), duration: ts10h));
            shifts.Add(new CSP.Models.Shift(name: "B+", start: GetTimeSpanHours(9), duration: ts9h));
            shifts.Add(new CSP.Models.Shift(name: "B++", start: GetTimeSpanHours(9), duration: ts10h));
            shifts.Add(new CSP.Models.Shift(name: "I+", start: GetTimeSpanHours(10), duration: ts9h));
            shifts.Add(new CSP.Models.Shift(name: "I++", start: GetTimeSpanHours(10), duration: ts10h));
            shifts.Add(new CSP.Models.Shift(name: "E+", start: GetTimeSpanHours(11), duration: ts9h));
            shifts.Add(new CSP.Models.Shift(name: "E++", start: GetTimeSpanHours(11), duration: ts10h));
            shifts.Add(new CSP.Models.Shift(name: "+D", start: GetTimeSpanHours(12), duration: ts9h));
            shifts.Add(new CSP.Models.Shift(name: "D++", start: GetTimeSpanHours(13), duration: ts10h));
            shifts.Add(new CSP.Models.Shift(name: "C+", start: GetTimeSpanHours(15), duration: ts9h));
            shifts.Add(new CSP.Models.Shift(name: "CL+", start: GetTimeSpanHours(16), duration: ts9h));
            shifts.Add(new CSP.Models.Shift(name: "++H", start: GetTimeSpanHours(15), duration: ts10h));
            solveShifts.Shifts = shifts;

            //Set requirements per shift
            int[]    liveData     = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 6, 7, 9, 11, 22, 25, 21, 32, 44, 38, 33, 48, 41, 54, 50, 42, 43, 45, 60, 62, 56, 44, 33, 22, 11, 18, 16, 24, 28, 6, 12, 15, 8, 6 };
            var      requirements = new List <CSP.Models.HalfHourRequirement>();
            TimeSpan ts           = GetTimeSpanHours(0);

            for (int i = 0; i < liveData.Length; i++)
            {
                requirements.Add(new CSP.Models.HalfHourRequirement(start: ts, requiredForce: liveData[i]));
                ts = ts.Add(ts30mi);
            }
            solveShifts.HalfHourRequirements = requirements;

            //pair shifts with vids
            Dictionary <CSP.Models.Shift, int> shiftsX;
            int             vidGoal;
            var             SX       = solveShifts.PrepareSimplexSolver(maxAgents: param1, shiftsExt: out shiftsX, vidGoal: out vidGoal);
            var             sxParams = new SimplexSolverParams();
            ILinearSolution solution = null;

            Task taskSolve = new Task(() =>
            {
                solution = SX.Solve(sxParams);
            });
            Stopwatch timer = new Stopwatch();

            timer.Start();
            taskSolve.Start();

            TimeSpan limit = new TimeSpan(hours: 0, minutes: 0, seconds: param3);

            while (!taskSolve.IsCompleted)
            {
                Console.SetCursorPosition(0, Console.CursorTop);
                Console.Write("  {0:hh}:{0:mm}:{0:ss}", timer.Elapsed);
                Thread.Sleep(millisecondsTimeout: 500);
            }
            Console.WriteLine("\n");

            timer.Stop();

            if (solution.Result == LinearResult.Feasible || solution.Result == LinearResult.Optimal)
            {
                Console.WriteLine(" solved as {1} after {0}", timer.Elapsed, solution.Result);
                Console.WriteLine("Goal: {0}", solution.GetValue(vidGoal).ToDouble());
                List <CSP.Models.ShiftForce> shiftsForce = new List <CSP.Models.ShiftForce>();
                foreach (var shift in shiftsX)
                {
                    var force = solution.GetValue(shift.Value).ToDouble();
                    shiftsForce.Add(new CSP.Models.ShiftForce(shift: shift.Key, force: (int)force));
                }
                solveShifts.ShowSolution(1, shiftsForce, showAgents: true, showSlots: true);
            }
            else
            {
                Console.WriteLine(" no solved :: {1} after {0}", timer.Elapsed, solution.Result);
            }
        }
예제 #7
0
        public virtual ILinearSolution Solve(ISolverParameters parameters)
        {
            lock (classLock)
            {
                if (env != null) /* If shutdown has already been called, env may be null.  */
                {
                    mosek.Task task = null;
                    task = new mosek.Task(env, 0, 0);
                    task.set_Stream(mosek.streamtype.log, null);
                    task.set_Stream(mosek.streamtype.msg, null);
                    task.set_Stream(mosek.streamtype.err, null);

                    MosekSolverParams mosekParams = parameters as MosekSolverParams;

                    interrupted    = false;
                    primalObjIsdef = false;

                    foreach (System.Diagnostics.TraceListener listener in mosekParams.GetListeners())
                    {
                        msgStream.AddListener(listener);
                    }

                    if (msgStream.listeners.Count > 0)
                    {
                        task.set_Stream(mosek.streamtype.log, msgStream);
                    }

                    mosekParams.LoadMosekParams(task);
                    progressCB = new MosekProgress(parameters.QueryAbort);

                    task.ProgressCB = progressCB;

                    if (disposed)
                    {
                        progressCB.Abort();
                    }

                    LoadData(task);

                    if (mosekParams.TaskDumpFileName != null)
                    {
                        task.writedata(mosekParams.TaskDumpFileName);
                    }

                    try
                    {
                        task.optimize();
                    }
                    catch (mosek.Warning w)
                    {
                        if (w.Code == mosek.rescode.trm_user_callback)
                        {
                            interrupted = true;
                            // feasible solutions ?
                            if (task.getintinf(mosek.iinfitem.mio_num_int_solutions) > 0)
                            {
                                foundIntSolution = true;
                            }
                        }
                    }
                    catch (mosek.Error e)
                    {
                        throw new MosekMsfException(e.ToString());
                    }

                    if (task.getintinf(mosek.iinfitem.mio_num_relax) > 0)
                    {
                        mipBestBound = task.getdouinf(dinfitem.mio_obj_bound);
                    }

                    task.solutionsummary(mosek.streamtype.log);

                    UpdateSolution(task);
                    progressCB = null;
                    if (task != null)
                    {
                        task.Dispose();
                        task = null;
                    }
                }
            }

            ILinearSolution sol = CreateLinearSolution();

            return(sol);
        }