当前位置: 首页>>代码示例>>C#>>正文


C# Constraint.ClearDfDv方法代码示例

本文整理汇总了C#中Constraint.ClearDfDv方法的典型用法代码示例。如果您正苦于以下问题:C# Constraint.ClearDfDv方法的具体用法?C# Constraint.ClearDfDv怎么用?C# Constraint.ClearDfDv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Constraint的用法示例。


在下文中一共展示了Constraint.ClearDfDv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Expand

        internal void Expand(Constraint violatedConstraint)
        {
            Debug_ClearDfDv(false /* forceFull */);

            // Calculate the derivative at the point of each constraint.
            // violatedConstraint's edge may be the minimum so pass null for variableDoneEval.
            // 
            // We also want to find the path along the active constraint tree from violatedConstraint.Left
            // to violatedConstraint.Right, and find the constraint on that path with the lowest Langragian
            // multiplier. The ActiveConstraints form a spanning tree so there will be no more than
            // one path. violatedConstraint is not yet active so it will not appear in this list.
            if (null == this.constraintPath)
            {
                this.constraintPath = new List<ConstraintDirectionPair>();
            }
            this.constraintPath.Clear();
            this.pathTargetVariable = violatedConstraint.Right;

#if VERBOSE
            Console.WriteLine("Before Block.Expand ComputeDfDv: {0}", this);
#endif // VERBOSE

            ComputeDfDv(violatedConstraint.Left);

#if VERBOSE
            Console.WriteLine("After Block.Expand ComputeDfDv: {0}", this);
            DumpState(null /* no prefix */);
#endif // VERBOSE

            // Now find the forward non-equality constraint on the path that has the minimal Lagrangina.
            // Both variables of the constraint are in the same block so a path should always be found.
            Constraint minLagrangianConstraint = null;
            if (this.constraintPath.Count > 0)
            {
                // We found an existing path so must remove an edge from our active list so that all 
                // connected variables from its varRight onward can move to the right; this will
                // make the "active" status false for that edge.  The active non-Equality constraint
                // with the minimal Lagrangian *that points rightward* is our split point (do *not*
                // split Equality constraints).
                foreach (ConstraintDirectionPair pathItem in this.constraintPath)
                {
#if VERBOSE
                    Console.WriteLine("ConstraintPath: {0} ({1})", pathItem.Constraint, pathItem.IsForward ? "forward" : "backward");
#endif // VERBOSE
                    if (pathItem.IsForward 
                            && ((null == minLagrangianConstraint) || (pathItem.Constraint.Lagrangian < minLagrangianConstraint.Lagrangian)))
                    {
                        if (!pathItem.Constraint.IsEquality)
                        {
                            minLagrangianConstraint = pathItem.Constraint;
                        }
                    }
                }
#if VERBOSE
                DumpPath("Expand path", minLagrangianConstraint);
#endif // VERBOSE
                if (null != minLagrangianConstraint)
                {
                    // Deactivate this constraint as we are splitting on it.
                    this.allConstraints.DeactivateConstraint(minLagrangianConstraint);
                }
            }

            this.constraintPath.Clear();
            this.pathTargetVariable = null;

            if (null == minLagrangianConstraint)
            {
                // If no forward non-equality edge was found, violatedConstraint would have created a cycle.
                Debug.Assert(!violatedConstraint.IsUnsatisfiable, "An already-unsatisfiable constraint should not have been attempted");
                violatedConstraint.IsUnsatisfiable = true;
                ++this.allConstraints.NumberOfUnsatisfiableConstraints;
#if VERBOSE
                Console.WriteLine("  -- Expand: No forward non-equality edge (minLagrangianConstraint) found, therefore the constraint is unsatisfiable -- ");
                Console.WriteLine("     Unsatisfiable constraint: {0}", violatedConstraint);
#endif // VERBOSE
                return;
            }

            // Note: for perf, expand in-place (as in Ipsep) rather than Split/Merge (as in the Scaling paper).

            // Adjust the offset of each variable at and past the right-hand side of violatedConstraint in the
            // active spanning tree.  Because we've removed minLagrangianConstraint, this will widen the
            // gap between minLagrangianConstraint.Left and .Right.  Note that this must include not only
            // violatedConstraint.Right and those to its right, but also those to its left that are connected
            // to it by active constraints - because the definition of an active constraint is that the
            // gap matches exactly with the actual position, so all will move as a unit.
            var lstConnectedVars = new List<Variable>();

            // We consider .Left "already evaluated" because we don't want the path evaluation to back
            // up to it (because we're splitting .Right off from it by deactivating the constraint).
            GetConnectedVariables(lstConnectedVars, violatedConstraint.Right, violatedConstraint.Left);
            double violation = violatedConstraint.Violation;
            int cConnectedVars = lstConnectedVars.Count;
            for (int ii = 0; ii < cConnectedVars; ++ii)
            {
                lstConnectedVars[ii].OffsetInBlock += violation;
            }

            // Now make the (no-longer-) violated constraint active.
//.........这里部分代码省略.........
开发者ID:danielskowronski,项目名称:network-max-flow-demo,代码行数:101,代码来源:Block.cs


注:本文中的Constraint.ClearDfDv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。