Ejemplo n.º 1
0
        private void PrepareSolver(AssignedVote assignedVote, bool useValueFunction, bool debugPrint = false)
        {
            _solver.Reset();

            float calculationTime = Time.NowSeconds;

            //_solver.AddCalculationTime(calculationTime);

            if (debugPrint)
            {
                Logger.Debug("=== TIME CONDITIONS ===");
            }
            for (int userNum = 0; userNum < _numUser; userNum++)
            {
                var userVoting = assignedVote.Votes[userNum];
                if (userVoting != null)
                {
                    if (debugPrint)
                    {
                        Logger.Debug("User " + userNum);
                    }
                    _solver.AddArrivalTimeForUser(userVoting.ArrivalTime, userNum);
                    if (useValueFunction)
                    {
                        _solver.AddValueFunction(userNum, UserPriorities[userNum], userVoting.ValueFunction);
                    }
                    _solver.AddConditions(userNum, userVoting.TimeConditions, debugPrint);
                }
            }
            if (debugPrint)
            {
                Logger.Debug("=======================");
            }
        }
        public override void ConsiderSelection(AssignedVote selectedVote)
        {
            for (int userNum = 0; userNum < selectedVote.Votes.Length; userNum++)
            {
                var userVote  = selectedVote.Votes[userNum];
                var userValue = GetUserValue(userVote, selectedVote);

                _valueHistory.AddFront(userNum, userValue);
            }
        }
        public override double GetUserValue(TransitionVote userVote, AssignedVote assignedVote)
        {
            var value = userVote.NormalizedValue;

            if (_useTimeValue)
            {
                value *= assignedVote.TimeValue;
            }
            if (userVote.Transition == VSUserTransition.Undefocus)
            {
                value /= 2;
            }
            return(value);
        }
Ejemplo n.º 4
0
        public virtual AssignedVote GetBestVote()
        {
            double       maxValue = double.MinValue;
            AssignedVote maxVote  = null;

            foreach (AssignedVote vote in AssignedVotes)
            {
                Logger.Debug($"{vote.TransitionName}, value {vote.Value}");
                if (maxValue < vote.Value)
                {
                    maxValue = vote.Value;
                    maxVote  = vote;
                }
            }

            return(maxVote == null || maxVote.Value <= 0 ? null : maxVote);
        }
Ejemplo n.º 5
0
        private void MaximumTimes(AssignedVote assignedVote, VoteTimeBucket bestBucket, out double maxPlanning,
                                  out double maxExec)
        {
            //Logger.Debug($"Times for {assignedVote.TransitionName}");
            maxPlanning = 0;
            maxExec     = 0;
            for (int userNum = 0; userNum < _numUsers; userNum++)
            {
                var userPlanning = assignedVote.Votes[userNum]
                                   .PlanningTimestampMs[bestBucket.UserNumToTimeNum[userNum]];
                var userExec = assignedVote.Votes[userNum]
                               .ExecutionLengthMs[bestBucket.UserNumToTimeNum[userNum]];

                //Logger.Debug($"User {userNum}: planning={userPlanning}, exec={userExec}");

                maxPlanning = Math.Max(userPlanning, maxPlanning);
                maxExec     = Math.Max(userExec, maxExec);
            }

            //Logger.Debug($"Max: planning={avgPlanning}, exec={avgExec}");
        }
Ejemplo n.º 6
0
        private void AvgTimes(AssignedVote assignedVote, VoteTimeBucket bestBucket, out double avgPlanning,
                              out double avgExec)
        {
            //Logger.Debug($"Times for {assignedVote.TransitionName}");
            avgPlanning = 0;
            avgExec     = 0;
            for (int userNum = 0; userNum < _numUsers; userNum++)
            {
                var userPlanning = assignedVote.Votes[userNum]
                                   .PlanningTimestampMs[bestBucket.UserNumToTimeNum[userNum]];
                var userExec = assignedVote.Votes[userNum]
                               .ExecutionLengthMs[bestBucket.UserNumToTimeNum[userNum]];

                //Logger.Debug($"User {userNum}: planning={userPlanning}, exec={userExec}");

                avgPlanning += userPlanning;
                avgExec     += userExec;
            }
            avgPlanning /= _numUsers;
            avgExec     /= _numUsers;
            //Logger.Debug($"Average: planning={avgPlanning}, exec={avgExec}");
        }
 public override double GetUserValue(TransitionVote userVote, AssignedVote assignedVote)
 {
     return(userVote.Value);
 }
 public override void ConsiderSelection(AssignedVote selectedVote)
 {
     _currentState = (_currentState + 1) % _choreo.Count;
 }
Ejemplo n.º 9
0
 public abstract double GetUserValue(TransitionVote userVote, AssignedVote assignedVote);
Ejemplo n.º 10
0
 public virtual void ConsiderSelection(AssignedVote selectedVote)
 {
 }
 public override double GetUserValue(TransitionVote userVote, AssignedVote assignedVote)
 {
     throw new System.NotImplementedException();
 }
        public override AssignedVote GetBestVote()
        {
            if (_bestVote != null)
            {
                return(_bestVote);
            }

            var lastValues = _valueHistory.GetAndRemoveLast();

            var qualities = new List <Quality>();

            foreach (var assignedVote in AssignedVotes)
            {
                double[] expectedValues = new double[_numUsers];
                //Logger.Debug("Vote: " + assignedVote.Transition);
                for (int userNum = 0; userNum < _numUsers; userNum++)
                {
                    var userVote = assignedVote.Votes[userNum];
                    expectedValues[userNum] = GetUserValue(userVote, assignedVote);

                    //Logger.Debug($"{userVote.Transition}: {userVote.Value}");
                }

                _valueHistory.AddAllLast(expectedValues);

                double expectedAvgAvg = _valueHistory.AverageAverage(UserPriorities);
                double expectedStd    = _valueHistory.StdOfAverageOfAverages(UserPriorities);

                qualities.Add(new Quality(assignedVote, expectedAvgAvg, expectedStd));

                //Logger.Debug($"{assignedVote.TransitionName}: Avg: {expectedAvgAvg}, Std: {expectedStd}");

                _valueHistory.GetAndRemoveLast();
            }

            _valueHistory.AddAllLast(lastValues);

            //qualities.Sort((tupleA, tupleB) => tupleA.Avg.CompareTo(tupleB.Avg));
            //int numConsidered = Math.Min(qualities.Count, NumBestAvgConsidered);

            //var bestQuality = qualities.Last();
            //var bestQualities = qualities.GetRange(qualities.Count - numConsidered, numConsidered);
            //var bestQuality = bestQualities.OrderBy(quality => quality.Sd).FirstOrDefault();

            // todo put in single for loop
            var bestAvg = qualities.Max(quality => quality.Avg);
            var bestSd  = qualities.Max(quality => quality.Sd);

            var     bestValue   = double.MinValue;
            Quality bestQuality = null;

            foreach (var quality in qualities)
            {
                var deltaBestAvg    = 1 - Math.Abs(quality.Avg - bestAvg);
                var deltaBestSd     = 1 - Math.Abs(quality.Sd - bestSd) / .5;
                var deltaOptimalAvg = quality.Avg;
                var deltaOptimalSd  = 1 - quality.Sd;
                //var value = deltaBestAvg * deltaBestAvg + 1.3 * deltaBestSd * deltaBestSd + deltaBestAvg * deltaBestSd;
                var value = 0D;
                //value += deltaOptimalAvg * deltaOptimalAvg;
                value += deltaOptimalAvg * deltaOptimalAvg + 1.3 * deltaOptimalSd * deltaOptimalSd + deltaOptimalAvg * deltaOptimalSd;
                if (bestValue < value)
                {
                    bestValue   = value;
                    bestQuality = quality;
                }
            }

            if (bestQuality == null)
            {
                Logger.Warn("AverageFairness: best vote is null");
                return(null);
            }

            Logger.Debug($"AverageFairness: best vote {bestQuality.Vote.TransitionName} selection creates history: avg={bestQuality.Avg}, sd={bestQuality.Sd}");

            _bestVote = bestQuality?.Vote;

            return(_bestVote);
        }
 public Quality(AssignedVote vote, double avg, double sd)
 {
     Vote = vote;
     Avg  = avg;
     Sd   = sd;
 }