Пример #1
0
        public PhraseCombineInfo(PowerPhraseData pd, PowerPhraseInfo p1, PowerPhraseInfo p2, CombineType combineType, PhraseMetricType metricType)
        {
            PrevPhrase = p1;
            NextPhrase = p2;
            this.CombineType = combineType;
            IntersectionLen = CalcIntersectionLen(p1.Phrase, p2.Phrase);
            if (combineType == CombineType.Overlap && IntersectionLen == 0)
                throw new Exception();

            CommandsStr = p2.Phrase.Substring(IntersectionLen);

            var fakeUnitState = new UnitState(new Cell(0, 0), 0);
            Commands = MovesPrinter.GetCommands(CommandsStr);
            MinX = 0;
            MaxX = 0;
            foreach (var cmd in Commands)
            {
                fakeUnitState = UnitState.MoveFuncs[cmd](fakeUnitState);
                MinX = Math.Min(MinX, fakeUnitState.Pivot.x);
                MaxX = Math.Max(MaxX, fakeUnitState.Pivot.x);
            }
            DY = fakeUnitState.Pivot.y;

            switch (combineType)
            {
                case CombineType.Overlap:
                    EffectiveLen = pd.CalcEffectiveLen(p1.Phrase + CommandsStr) - p1.EffectiveLength;
                    break;
                case CombineType.Append:
                    EffectiveLen = p2.EffectiveLength;
                    break;
                case CombineType.MoveDownAppend:
                    EffectiveLen = p2.EffectiveLength;
                    ++DY;
                    break;
            }

            switch (metricType)
            {
                case PhraseMetricType.Div:
                    Metric = (double)EffectiveLen / DY;
                    break;
                case PhraseMetricType.Diff:
                    Metric = (double)EffectiveLen - DY;
                    break;
                case PhraseMetricType.Div2:
                    Metric = (double)EffectiveLen / (DY + LAST_MOVE_PENALTY[Commands[Commands.Length - 1]]);
                    break;
                case PhraseMetricType.Div3:
                    Metric = (double)EffectiveLen / (DY + LAST_MOVE_PENALTY[Commands[Commands.Length - 1]] * 2);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("metricType");
            }

            DebugPrinter.WriteLine("Phrase combine: \"{0}\" and \"{1}\" with type {2}, effective len {3}, DY {4}, metric {5}",
                p1.Phrase, p2.Phrase, combineType, EffectiveLen, DY, Metric);
        }
Пример #2
0
        public PowerPhraseData(PowerPhraseInfo[] phrases, PhraseMetricType metricType)
        {
            Phrases = phrases;
            //_combineInfo = new CombineInfo[phrases.Length, phrases.Length];

            foreach (var p in Phrases)
                p.EffectiveLength = CalcEffectiveLen(p.Phrase);

            foreach (var p1 in phrases)
            {
                p1.InitCombinations(this, metricType);
            }
        }
Пример #3
0
        public ArgParser(string[] args)
        {
            InputFileNames = new List<string>();
            PowerPhrases = new List<string>();

            for (int i = 0; i < args.Length; ++i)
            {
                switch(args[i])
                {
                    case "-f":
                        ++i;
                        InputFileNames.Add(args[i]);
                        break;
                    case "-t":
                        ++i;
                        TimeLimit = int.Parse(args[i]);
                        break;
                    case "-m":
                        ++i;
                        MemoryLimit = int.Parse(args[i]);
                        break;
                    case "-c":
                        ++i;
                        NumCores = int.Parse(args[i]);
                        break;
                    case "-p":
                        ++i;
                        PowerPhrases.Add(args[i].ToLowerInvariant());
                        break;

                    case "-metric":
                        ++i;
                        PhraseMetricType = (PhraseMetricType)Enum.Parse(typeof (PhraseMetricType), args[i], true);
                        break;
                }
            }
        }
Пример #4
0
        public void InitCombinations(PowerPhraseData pd, PhraseMetricType metricType)
        {
            PhraseCombinations.Clear();
            foreach (var p2 in pd.Phrases)
            {
                if (p2.Phrase.Length == 0)
                    continue;

                foreach (CombineType combineType in Enum.GetValues(typeof(CombineType)))
                {
                    try
                    {
                        PhraseCombinations.Add(new PhraseCombineInfo(pd, this, p2, combineType, metricType));
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            //PhraseCombinations.Sort((pc1, pc2) => pc2.Metric.CompareTo(pc1.Metric));
        }