public ConstraintOperationResult FinishAddingConstraintFixedLength(double length) { var e = addingEdgeConstraintOrVerticeState.selectedEdge; addingEdgeConstraintOrVerticeState.constraint = new FixedLengthConstraint(length); var constraint = addingEdgeConstraintOrVerticeState.constraint; drawingModule.BeginDrawingTransaction(); drawingModule.ClearPolygonBorders(e.Parent); drawingModule.ClearPolygonFilling(e.Parent); ConstraintOperationResult canAccStart, canAccEnd = null; // firstly checks with startX (double x_end, double y_end) = (e.end.X, e.end.Y); // if lenght from prompt is different than edge's lenght - calculate new coordinates if (e.Length != length) { (x_end, y_end) = CalculateLocationForFixedLengthFromStart(e, length); } canAccStart = e.AddConstraintAndApplyWithCheck(constraint, e.start.X, e.start.Y, x_end, y_end); if (!canAccStart.Success) { //then check accorindg to endX // if length from prompt is different than edge's lenght - calculate new coordinates (double x_start, double y_start) = (e.start.X, e.start.Y); if (e.Length != length) { (x_start, y_start) = CalculateLocationForFixedLengthFromEnd(e, length); } canAccEnd = e.AddConstraintAndApplyWithCheck(constraint, x_start, y_start, e.end.X, e.end.Y); } Redraw(); drawingModule.FinishDrawingTransaction(); addingEdgeConstraintOrVerticeState.Clear(); if (canAccStart != null && canAccStart.Success) { return(canAccStart); } if (canAccEnd != null && canAccEnd.Success) { return(canAccEnd); } if (canAccStart != null) { return(canAccStart); } if (canAccEnd != null) { return(canAccEnd); } return(new ConstraintOperationResult(false, ConstraintOperationKind.AddAndApplyWithCheck, TEXTS.UNKNOWN_ERROR)); }
void IConstraint.Propagate(out ConstraintOperationResult result) { var enforce = new Bounds <int>(1, 1); do { Propagate(enforce, out result); } while ((result &= ConstraintOperationResult.Propagated) == ConstraintOperationResult.Propagated); }
public override void Propagate(Bounds <int> enforceBounds, out ConstraintOperationResult result) { left.GetUpdatedBounds(); if (right != null) { right.GetUpdatedBounds(); } var propagated = false; var intermediateResult = propagator((ExpressionInteger)left, (ExpressionInteger)right, enforceBounds); while (intermediateResult == ConstraintOperationResult.Propagated) { var leftResult = ConstraintOperationResult.Undecided; var rightResult = ConstraintOperationResult.Undecided; if (!left.IsBound) { left.Propagate(left.Bounds, out leftResult); } if (right != null && !right.IsBound) { right.Propagate(right.Bounds, out rightResult); } intermediateResult = (leftResult | rightResult) & ConstraintOperationResult.Propagated; if (intermediateResult != ConstraintOperationResult.Propagated) { continue; } propagated = true; intermediateResult = propagator((ExpressionInteger)left, (ExpressionInteger)right, enforceBounds); } if (intermediateResult == ConstraintOperationResult.Violated) { result = ConstraintOperationResult.Violated; } else { result = propagated ? ConstraintOperationResult.Propagated : ConstraintOperationResult.Undecided; } }
public override void Propagate(Bounds <int> enforceBounds, out ConstraintOperationResult result) { result = ConstraintOperationResult.Undecided; if (this.State == null) { return; } var domainIntStack = this.domainStack.Peek(); var isDomainNew = false; IDomain <int> propagatedDomain; if (domainIntStack.Depth == this.State.Depth) { propagatedDomain = domainIntStack.Domain; } else { isDomainNew = true; propagatedDomain = (IDomain <int>)domainIntStack.Domain.Clone(); this.domainStack.Push(new DomInt(propagatedDomain, this.State.Depth)); } var domainResult = DomainOperationResult.RemoveSuccessful; while (enforceBounds.LowerBound > propagatedDomain.LowerBound && domainResult == DomainOperationResult.RemoveSuccessful) { propagatedDomain.Remove(propagatedDomain.LowerBound, out domainResult); result = ConstraintOperationResult.Propagated; } while (enforceBounds.UpperBound < propagatedDomain.UpperBound && domainResult == DomainOperationResult.RemoveSuccessful) { propagatedDomain.Remove(propagatedDomain.UpperBound, out domainResult); result = ConstraintOperationResult.Propagated; } if (isDomainNew && result != ConstraintOperationResult.Propagated) { this.domainStack.Pop(); } }
void IConstraint.Propagate(out ConstraintOperationResult result) { this.Graph = new BipartiteGraph(this.variableArray); if (!FindMatching()) { result = ConstraintOperationResult.Violated; return; } this.cycleDetection.Graph = this.Graph; this.cycleDetection.DetectCycle(); result = ConstraintOperationResult.Undecided; foreach (var cycle in this.cycleDetection.StronglyConnectedComponents) { foreach (var node in cycle) { if (!(node is NodeVariable) || node == this.Graph.NullNode) { continue; } var variable = ((NodeVariable)node).Variable; foreach (var value in variable.Domain.Cast <int>().Where(value => this.Graph.Values[value].CycleIndex != node.CycleIndex && ((NodeValue)this.Graph.Pair[node]).Value != value)) { result = ConstraintOperationResult.Propagated; DomainOperationResult domainResult; ((IVariable <int>)variable).Remove(value, this.Depth, out domainResult); if (domainResult != DomainOperationResult.EmptyDomain) { continue; } result = ConstraintOperationResult.Violated; return; } } } }
public ConstraintOperationResult FinishAddingConstraintHorizontalEdge() { var e = addingEdgeConstraintOrVerticeState.selectedEdge; addingEdgeConstraintOrVerticeState.constraint = new HorizontalEdgeConstraint(); var constraint = addingEdgeConstraintOrVerticeState.constraint; drawingModule.BeginDrawingTransaction(); drawingModule.ClearPolygonBorders(e.Parent); drawingModule.ClearPolygonFilling(e.Parent); ConstraintOperationResult canAccStart, canAccEnd = null; // firstly checks with startX canAccStart = e.AddConstraintAndApplyWithCheck(constraint, e.start.X, e.start.Y, e.end.X, e.start.Y); if (!canAccStart.Success) { //then check accorindg to endX canAccEnd = e.AddConstraintAndApplyWithCheck(constraint, e.start.X, e.end.Y, e.end.X, e.end.Y); } Redraw(); drawingModule.FinishDrawingTransaction(); addingEdgeConstraintOrVerticeState.Clear(); if (canAccStart != null && canAccStart.Success) { return(canAccStart); } if (canAccEnd != null && canAccEnd.Success) { return(canAccEnd); } if (canAccStart != null) { return(canAccStart); } if (canAccEnd != null) { return(canAccEnd); } return(new ConstraintOperationResult(false, ConstraintOperationKind.AddAndApplyWithCheck, TEXTS.UNKNOWN_ERROR)); }
void IConstraint.Check(out ConstraintOperationResult result) { for (var i = 0; i < this.variableArray.Length; ++i) { this.domainArray[i] = variableArray[i].Domain; } if (!FindMatching()) { result = ConstraintOperationResult.Violated; return; } if (this.variableArray.Cast <IVariable <int> >().Any(variable => !variable.Instantiated())) { result = ConstraintOperationResult.Undecided; return; } result = ConstraintOperationResult.Satisfied; }
void IConstraint.Check(out ConstraintOperationResult result) { for (var i = 0; i < this.variableArray.Length; ++i) { this.domainArray[i] = ((VariableInteger)variableArray[i]).Domain; } if (this.variableArray.Any(variable => !variable.Instantiated())) { result = ConstraintOperationResult.Undecided; return; } try { result = this.Value != 0 ? ConstraintOperationResult.Satisfied : ConstraintOperationResult.Violated; } catch (DivideByZeroException) { result = ConstraintOperationResult.Violated; } }
public abstract void Propagate(Bounds <T> enforceBounds, out ConstraintOperationResult result);