Exemplo n.º 1
0
 // (i-j)*(i-j)*coefficient is added to the goal
 static void AddGoalTwoNodesAreClose(VariableDef i, VariableDef j, double weight)
 {
     SfServ.Decision x    = GetOrCreateDecision(i);
     SfServ.Decision y    = GetOrCreateDecision(j);
     SfServ.Term     term = weight * (x * x - 2 * x * y + y * y);
     AddTermToGoalTerm(term);
 }
Exemplo n.º 2
0
 static void AddTermToGoalTerm(SfServ.Term term)
 {
     if (null == (object)goalTerm)
     {
         goalTerm = term;
     }
     else
     {
         goalTerm += term;
     }
 }
Exemplo n.º 3
0
        // meaning that we would like position i at "position"
        static void AddNodeWithIdealPosition(VariableDef varDef)
        {
            double weight   = varDef.WeightX;
            double position = varDef.DesiredPosX;

            SfServ.Decision x = GetOrCreateDecision(varDef);

            //adding the term (ix-pos)^2; workaround for bug processing x(x - 2*position)
            SfServ.Term term = weight * (x * x - 2 * position * x);
            //model.AddConstraint(varDef.Ordinal.ToString() + "ttt", x >= -100000.0);    // TODO: hack to make the solver happy - fix it later!!!!
            AddTermToGoalTerm(term);
            return;
        }
Exemplo n.º 4
0
        static void StaticReset()
        {
#if SIMPLESOLVER
            solver    = null;
            goal      = 0;
            numOfRows = -1;
#else  // SIMPLESOLVER
            solution = null;
            Context.ClearModel();
            model = Context.CreateModel();
            Constraints.Clear();
            goalTerm = null;
            solution = null;
            goal     = null;
#endif // SIMPLESOLVER
        }
Exemplo n.º 5
0
 static bool Solve()
 {
     if (null != goal)
     {
         model.RemoveGoal(goal);
     }
     if (null == (object)goalTerm)
     {
         goalTerm = 0;
     }
     goal     = model.AddGoal("goal", SfServ.GoalKind.Minimize, goalTerm);
     solution = Context.Solve();
     if (TestGlobals.VerboseLevel >= 2)
     {
         SfServ.Report report = solution.GetReport();
         System.Diagnostics.Debug.WriteLine(report.ToString());
     }
     return(solution.Quality == SfServ.SolverQuality.Optimal);
 }
        static void StaticReset()
        {
#if SIMPLESOLVER
            solver = null;
            goal = 0;
            numOfRows = -1;
#else  // SIMPLESOLVER
            solution = null;
            Context.ClearModel();
            model = Context.CreateModel();
            Constraints.Clear();
            goalTerm = null;
            solution = null;
            goal = null;
#endif // SIMPLESOLVER
        }
 static bool Solve()
 {
     if (null != goal)
     {
         model.RemoveGoal(goal);
     }
     if (null == (object)goalTerm)
     {
         goalTerm = 0;
     }
     goal = model.AddGoal("goal", SfServ.GoalKind.Minimize, goalTerm);
     solution = Context.Solve();
     if (TestGlobals.VerboseLevel >= 2)
     {
         SfServ.Report report = solution.GetReport();
         Console.WriteLine(report.ToString());
     }
     return solution.Quality == SfServ.SolverQuality.Optimal;
 }
 static void AddTermToGoalTerm(SfServ.Term term)
 {
     if (null == (object)goalTerm)
     {
         goalTerm = term;
     }
     else
     {
         goalTerm += term;
     }
 }