Exemplo n.º 1
0
        public ARmDataSet MergeDataSet(IEnumerable <ARmDataSet> list, string expand, MergingMode mode, Func <IEnumerable <ARmDataSet>, string, MergingMode, ARmDataSet> del)
        {
            ARmDataSet dataSet = del(list, expand, mode);

            string rmType = Base.Report.Current.Type;

            if (rmType == ARmReport.PM)
            {
                foreach (ARmDataSet set in list)
                {
                    if (set == null)
                    {
                        continue;
                    }

                    RMReportWildcard.ConcatenateRangeWithDataSet(dataSet, set, Keys.StartAccountGroup, Keys.EndAccountGroup, mode);
                    RMReportWildcard.ConcatenateRangeWithDataSet(dataSet, set, Keys.StartProject, Keys.EndProject, mode);
                    RMReportWildcard.ConcatenateRangeWithDataSet(dataSet, set, Keys.StartProjectTask, Keys.EndProjectTask, mode);
                    RMReportWildcard.ConcatenateRangeWithDataSet(dataSet, set, Keys.StartInventory, Keys.EndInventory, mode);
                }

                dataSet.Expand = list.First().Expand;
            }

            return(dataSet);
        }
Exemplo n.º 2
0
        public bool IsRedundant(string move)
        {
            // TODO - add support for MERGE_REDUNDANT_MOVES_PRESERVE_STATE
            //MergingMode mergingMode = preserveState ? MergingMode.MERGE_REDUNDANT_MOVES_PRESERVE_STATE : MergingMode.CANONICALIZE_MOVES;
            const MergingMode mode = MergingMode.CanonicalizeMoves;
            var indexAndMove       = FindBestIndexForMove(move, mode);

            return(indexAndMove.Index < _moves.Count || indexAndMove.Move == null);
        }
        public static void ConcatenateRangeWithDataSet(ARmDataSet target, ARmDataSet source, object startKey, object endKey, MergingMode mergingMode)
        {
            string startValue = (source[startKey] as string ?? String.Empty);
            string endValue   = (source[endKey] as string ?? String.Empty);
            char   mergeChar  = default(char);

            switch (mergingMode)
            {
            case MergingMode.Intersection:
                mergeChar = RMReportConstants.RangeIntersectionChar;
                break;

            case MergingMode.Union:
                mergeChar = RMReportConstants.RangeUnionChar;
                break;

            default:
                throw new NotSupportedException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.MergingModeNotSupported, mergingMode));
            }

            if (!(startValue == String.Empty && endValue == String.Empty))
            {
                if (startValue.Contains(RMReportConstants.RangeDelimiterChar) && endValue != String.Empty)
                {
                    throw new ArgumentException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.ValueShouldBeEmpty, startKey, startValue, endKey, endValue));
                }
                else if (startValue == String.Empty && endValue != String.Empty)
                {
                    throw new ArgumentException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.DataSourceIncomplete, endKey, startKey, endValue));
                }

                if (!String.IsNullOrEmpty(target[startKey] as string))
                {
                    // There's existing data stored; we will intersect/union previous range with this new range at a later stage
                    target[startKey] += mergeChar.ToString();
                }

                target[startKey] += startValue;
                if (endValue != String.Empty)
                {
                    target[startKey] += RMReportConstants.RangeDelimiterChar.ToString() + endValue;
                }
            }
        }
Exemplo n.º 4
0
        public IndexAndMove FindBestIndexForMove(string move, MergingMode mergingMode)
        {
            if (mergingMode == MergingMode.NoMerging)
            {
                return(new IndexAndMove(_moves.Count, move));
            }

            var newUnNormalizedState = _unNormalizedState.Apply(move);

            if (newUnNormalizedState.EqualsNormalized(_unNormalizedState))
            {
                if (mergingMode == MergingMode.CanonicalizeMoves)
                {
                    return(new IndexAndMove(0, null));
                }
            }
            var newNormalizedState = newUnNormalizedState.GetNormalized();

            var successors = GetState().GetCanonicalMovesByState();

            // Search for the right move to do to our current state in
            // order to match up with newNormalizedState.
            move = (from ps in successors.Keys
                    where ps.EqualsNormalized(newNormalizedState)
                    select successors[ps]).FirstOrDefault();
            // One of getStates()'s successors must be newNormalizedState.
            // If not, something has gone very wrong.
            Assert(move != null);

            if (mergingMode != MergingMode.CanonicalizeMoves)
            {
                return(new IndexAndMove(_moves.Count, move));
            }
            for (var lastMoveIndex = _moves.Count - 1; lastMoveIndex >= 0; lastMoveIndex--)
            {
                var lastMove            = _moves[lastMoveIndex];
                var stateBeforeLastMove = _states[lastMoveIndex];
                if (!stateBeforeLastMove.MovesCommute(lastMove, move))
                {
                    break;
                }
                var stateAfterLastMove           = _states[lastMoveIndex + 1];
                var stateAfterLastMoveAndNewMove = stateAfterLastMove.Apply(move);

                if (stateBeforeLastMove.EqualsNormalized(stateAfterLastMoveAndNewMove))
                {
                    return(new IndexAndMove(lastMoveIndex, null));
                }
                successors = stateBeforeLastMove.GetCanonicalMovesByState();
                foreach (var ps in successors.Keys)
                {
                    if (!ps.EqualsNormalized(stateAfterLastMoveAndNewMove))
                    {
                        continue;
                    }
                    var alternateLastMove = successors[ps];
                    // move merges with lastMove
                    return(new IndexAndMove(lastMoveIndex, alternateLastMove));
                }
            }
            return(new IndexAndMove(_moves.Count, move));
        }
Exemplo n.º 5
0
 public AlgorithmBuilder(MergingMode mergingMode, PuzzleState originalState)
 {
     _mergingMode = mergingMode;
     ResetToState(originalState);
 }
Exemplo n.º 6
0
        public static void ConcatenateRangeWithDataSet(ARmDataSet target, ARmDataSet source, object startKey, object endKey, MergingMode mergingMode)
        {
            string startValue = (source[startKey] as string ?? String.Empty);
            string endValue   = (source[endKey] as string ?? String.Empty);
            char   mergeChar  = default(char);

            switch (mergingMode)
            {
            case MergingMode.Intersection:
                mergeChar = RMReportConstants.RangeIntersectionChar;
                break;

            case MergingMode.Union:
                mergeChar = RMReportConstants.RangeUnionChar;
                break;

            default:
                throw new NotSupportedException(String.Format("Merging mode '{0}' is not supported.", mergingMode));
            }

            if (!(startValue == String.Empty && endValue == String.Empty))
            {
                if (startValue.Contains(RMReportConstants.RangeDelimiterChar) && endValue != String.Empty)
                {
                    throw new ArgumentException(String.Format("A range is specified in {0}; end value should be empty. {0}: {1}. {2}: {3}.", startKey, startValue, endKey, endValue));
                }
                else if (startValue == String.Empty && endValue != String.Empty)
                {
                    throw new ArgumentException(String.Format("Data Source is incomplete. If you set {0}, you should also define {1}. {0}: {2}.", endKey, startKey, endValue));
                }

                if (!String.IsNullOrEmpty(target[startKey] as string))
                {
                    // There's existing data stored; we will intersect/union previous range with this new range at a later stage
                    target[startKey] += mergeChar.ToString();
                }

                target[startKey] += startValue;
                if (endValue != String.Empty)
                {
                    target[startKey] += RMReportConstants.RangeDelimiterChar.ToString() + endValue;
                }
            }
        }