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 SfServ.Decision GetOrCreateDecision(VariableDef varDef)
 {
     if (null == varDef.VariableX)
     {
         var d = new SfServ.Decision(SfServ.Domain.Real, varDef.Ordinal.ToString());
         varDef.VariableX = new SfVariable(d);
         model.AddDecision(d);
         return(d);
     }
     return(((SfVariable)varDef.VariableX).Decision);
 }
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
        // leftNode+gap leq RightNode
        static void AddLeftRightSeparationConstraint(VariableDef leftNode, VariableDef rightNode, double gap, bool isEquality)
        {
            SfServ.Decision leftDecision  = GetOrCreateDecision(leftNode);
            SfServ.Decision rightDecision = GetOrCreateDecision(rightNode);

            SfServ.Term term;
            if (isEquality)
            {
                term = (leftDecision * leftNode.ScaleX) + gap == (rightDecision * rightNode.ScaleX);
            }
            else
            {
                term = (leftDecision * leftNode.ScaleX) + gap <= (rightDecision * rightNode.ScaleX);
            }
            Constraints.Add(model.AddConstraint(Constraints.Count.ToString(), term));
        }
Exemplo n.º 5
0
 internal SfVariable(SfServ.Decision d)
 {
     this.Decision = d;
 }
 static SfServ.Decision GetOrCreateDecision(VariableDef varDef)
 {
     if (null == varDef.VariableX)
     {
         var d = new SfServ.Decision(SfServ.Domain.Real, varDef.Ordinal.ToString());
         varDef.VariableX = new SfVariable(d);
         model.AddDecision(d);
         return d;
     }
     return ((SfVariable)varDef.VariableX).Decision;
 }
 internal SfVariable(SfServ.Decision d)
 {
     this.Decision = d;
 }