Exemple #1
0
        public IEnumerable <double> ResolveStrains(TriaxialTest _traxialTest, double[] pointsOfIntrest)
        {
            var list = new List <double>();

            foreach (var point in pointsOfIntrest)
            {
                _estimator.EstimatorData = _baseData.GetFilteredDataByStressRelative();
                list.Add(_estimator.Estimate(point));
            }
            return(list);
        }
Exemple #2
0
        public List <ActionBase> SolvePart(State state)
        {
            //Console.Out.WriteLine("START PART");

            var bestEstimation             = double.MinValue;
            List <ActionBase> bestSolution = null;

            for (int i = 0; i < tryCount; i++)
            {
                var clone      = state;//.Clone();
                var undoes     = new List <Action>();
                var solution   = SolveStep(clone, undoes);
                var estimation = estimator.Estimate(clone, state.SingleWorker);
                undoes.Reverse();
                foreach (var undo in undoes)
                {
                    undo();
                }
                //Console.Out.Write($"  {estimation} {solution.Format()}");
                if (estimation > bestEstimation)
                {
                    bestEstimation = estimation;
                    bestSolution   = solution;
                    //Console.Out.WriteLine(" -- better");
                }

                // else
                //     Console.Out.WriteLine();
            }

            return(bestSolution);
        }
Exemple #3
0
        private (ActionBase action, double score) EstimateAction(ActionBase action, State state)
        {
            var undo  = state.Apply(action);
            var score = estimator.Estimate(state, state.SingleWorker);

            undo();
            return(action, score);
        }
Exemple #4
0
        private void ApplyRecursion(TreeNode <Block> node, int recDepth)
        {
            if (recDepth == _depth - 1)
            {
                _currentEstimator = _estimators.Last();
            }
            else
            {
                _currentEstimator = _estimators.First();
            }

            var nextTurns = getNextTurns(node.GameState);

            if (nextTurns.Count == 0)
            {
                node.Score = _currentEstimator.Estimate(node.GameState);
                return;
            }

            if (recDepth == _depth)
            {
                return;
            }

            if (node.Children == null)
            {
                node.Children = new List <TreeNode <Block> >();
                foreach (var(block, score) in nextTurns)
                {
                    var currentGameState = node.GameState.copy();
                    currentGameState.deleteBlock(block);
                    node.Children.Add(new TreeNode <Block>(score, null, node, block,
                                                           currentGameState));
                }
            }

            foreach (var child in node.Children)
            {
                ApplyRecursion(child, recDepth + 1);
            }
        }
Exemple #5
0
        public static List <IRecommendedItem> GetTopItems(int howMany,
                                                          IEnumerator <long> possibleItemIDs,
                                                          IDRescorer rescorer,
                                                          IEstimator <long> estimator)
        {
            //Preconditions.checkArgument(possibleItemIDs != null, "possibleItemIDs is null");
            //Preconditions.checkArgument(estimator != null, "estimator is null");

            var    topItems       = new SortedSet <IRecommendedItem>(ByValueRecommendedItemComparator.getReverseInstance());
            bool   full           = false;
            double lowestTopValue = Double.NegativeInfinity;

            while (possibleItemIDs.MoveNext())
            {
                long itemID = possibleItemIDs.Current;
                if (rescorer == null || !rescorer.isFiltered(itemID))
                {
                    double preference;
                    try {
                        preference = estimator.Estimate(itemID);
                    } catch (NoSuchItemException nsie) {
                        continue;
                    }
                    double rescoredPref = rescorer == null ? preference : rescorer.rescore(itemID, preference);
                    if (!Double.IsNaN(rescoredPref) && (!full || rescoredPref > lowestTopValue))
                    {
                        topItems.Add(new GenericRecommendedItem(itemID, (float)rescoredPref));
                        if (full)
                        {
                            topItems.Remove(topItems.Min);
                        }
                        else if (topItems.Count > howMany)
                        {
                            full = true;
                            topItems.Remove(topItems.Min); //     topItems.poll();
                        }
                        lowestTopValue = topItems.Min.GetValue();
                    }
                }
            }
            int size = topItems.Count;

            if (size == 0)
            {
                return(new List <IRecommendedItem>());
            }
            List <IRecommendedItem> result = new List <IRecommendedItem>(size);

            result.AddRange(topItems);
            result.Reverse();
            //Collections.sort(result, ByValueRecommendedItemComparator.getInstance());
            return(result);
        }
Exemple #6
0
        public static long[] GetTopUsers(int howMany,
                                         IEnumerator <long> allUserIDs,
                                         IDRescorer rescorer,
                                         IEstimator <long> estimator)
        {
            var    topUsers       = new SortedSet <SimilarUser>();
            bool   full           = false;
            double lowestTopValue = Double.NegativeInfinity;

            while (allUserIDs.MoveNext())
            {
                long userID = allUserIDs.Current;
                if (rescorer != null && rescorer.isFiltered(userID))
                {
                    continue;
                }
                double similarity;
                try {
                    similarity = estimator.Estimate(userID);
                } catch (NoSuchUserException nsue) {
                    continue;
                }
                double rescoredSimilarity = rescorer == null ? similarity : rescorer.rescore(userID, similarity);
                if (!Double.IsNaN(rescoredSimilarity) && (!full || rescoredSimilarity > lowestTopValue))
                {
                    topUsers.Add(new SimilarUser(userID, rescoredSimilarity));
                    if (full)
                    {
                        topUsers.Remove(topUsers.Max); // topUsers.poll();
                    }
                    else if (topUsers.Count > howMany)
                    {
                        full = true;
                        topUsers.Remove(topUsers.Max); // topUsers.poll();
                    }
                    lowestTopValue = topUsers.Max.getSimilarity();
                }
            }
            int size = topUsers.Count;

            if (size == 0)
            {
                return(NO_IDS);
            }
            List <SimilarUser> sorted = new List <SimilarUser>(size);

            return(topUsers.Select(s => s.getUserID()).ToArray());
        }
Exemple #7
0
        private Block getNextTurn(GameState curGameState)
        {
            var   initialLegals = curGameState.legals();
            Block bestTurn      = null;
            var   bestTurnScore = double.MinValue;


            foreach (var block in initialLegals)
            {
                var mutableGameState = curGameState.copy();
                mutableGameState.deleteBlock(block);
                var curScore = _estimator.Estimate(mutableGameState);
                if (!(curScore > bestTurnScore))
                {
                    continue;
                }
                bestTurn      = block;
                bestTurnScore = curScore;
            }

            return(bestTurn);
        }
Exemple #8
0
        public List <ActionBase> SolvePart(State state, List <List <ActionBase> > partialSolution)
        {
            var bestEstimation             = double.MinValue;
            List <ActionBase> bestSolution = null;

            var usedClonings     = partialSolution.Sum(x => x.Count(c => c is UseCloning));
            var useCloningsLocal = partialSolution.Count == 0 &&
                                   state.CloningCount - usedClonings > 0 &&
                                   state.Boosters.Any(b => b.Type == BoosterType.MysteriousPoint && b.Position == state.Workers[0].Position); //only first worker can use cloning

            var usedWheels     = partialSolution.Sum(x => x.Count(c => c is UseFastWheels));
            var useWheelsLocal = useWheels && (state.FastWheelsCount - usedWheels) > 0;

            var usedDrill     = partialSolution.Sum(x => x.Count(c => c is UseDrill));
            var useDrillLocal = useDrill && (state.DrillCount - usedDrill) > 0;

            foreach (var chain2 in chains)
            {
                var chain = chain2.ToList();
                if (useCloningsLocal)
                {
                    chain.Insert(0, new UseCloning());
                    chain.RemoveAt(chain.Count - 1);
                }
                if (useWheelsLocal)
                {
                    chain.Insert(0, new UseFastWheels());
                    chain.RemoveAt(chain.Count - 1);
                }
                if (useDrillLocal)
                {
                    chain.Insert(0, new UseDrill());
                    chain.RemoveAt(chain.Count - 1);
                }
                var solution = new List <ActionBase>();
                var undos    = new List <Action>();
                for (var c = 0; c < chain.Count; c++)
                {
                    var action = chain[c];
                    if (action is Move moveAction)
                    {
                        var worker       = state.Workers[partialSolution.Count];
                        var nextPosition = worker.Position + moveAction.Shift;
                        if (!nextPosition.Inside(state.Map) || (state.Map[nextPosition] == CellState.Obstacle && worker.DrillTimeLeft <= 1))
                        {
                            break;
                        }
                    }

                    undos.Add(state.Apply(
                                  state
                                  .Workers
                                  .Select(
                                      (w, i) => (w, i < partialSolution.Count ? partialSolution[i][c]
                                    : i == partialSolution.Count ? action
                                    : new Wait()))
                                  .ToList()));
                    solution.Add(action);
                    if (state.UnwrappedLeft == 0)
                    {
                        break;
                    }
                }

                while (solution.Count < depth)
                {
                    var wait = new Wait();
                    undos.Add(state.Apply(
                                  state
                                  .Workers
                                  .Select((w, i) => (w, i < partialSolution.Count ? partialSolution[i][solution.Count] : wait))
                                  .ToList()));
                    solution.Add(wait);
                }

                var estimation = estimator.Estimate(state, state.Workers[partialSolution.Count]);
                //Console.Out.Write($"  w{partialSolution.Count} {estimation} {solution.Format()}");
                if (estimation > bestEstimation)
                {
                    bestEstimation = estimation;
                    bestSolution   = solution;
                    //Console.Out.WriteLine(" -- better");
                }

                /*else
                 *  Console.Out.WriteLine();*/

                undos.Reverse();
                foreach (var undo in undos)
                {
                    undo();
                }
            }

            return(bestSolution);
        }