Example #1
0
        private SolutionAgg HandleDifference(SolutionAgg first, SolutionAgg second)
        {
            // Can we combine the currentSol with this existent solution?
            IndexList diffIndices = IndexList.DifferenceIndices(first.atomIndices, second.atomIndices);

            // Disjoint union not possible.
            if (diffIndices == null)
            {
                return(null);
            }

            //
            // Can combine; create a new solution / equation with addition.
            //
            SolutionAgg newSum = new SolutionAgg();

            newSum.atomIndices = diffIndices;
            newSum.solType     = first.solType == SolutionAgg.SolutionType.COMPUTABLE &&
                                 second.solType == SolutionAgg.SolutionType.COMPUTABLE ? SolutionAgg.SolutionType.COMPUTABLE : SolutionAgg.SolutionType.INCOMPUTABLE;
            if (newSum.solType == SolutionAgg.SolutionType.INCOMPUTABLE)
            {
                newSum.solArea = -1;
            }
            else
            {
                newSum.solArea = first.solArea > second.solArea ? first.solArea - second.solArea : second.solArea - first.solArea;
            }

            if (first.atomIndices.Count > second.atomIndices.Count)
            {
                newSum.solEq = new ComplexRegionEquation(MakeRegion(diffIndices.orderedIndices),
                                                         new ComplexRegionEquation.Binary(first.solEq.target, OperationT.SUBTRACTION, second.solEq.target));
            }
            else
            {
                newSum.solEq = new ComplexRegionEquation(MakeRegion(diffIndices.orderedIndices),
                                                         new ComplexRegionEquation.Binary(second.solEq.target, OperationT.SUBTRACTION, first.solEq.target));
            }

            return(newSum);
        }