示例#1
0
        void channel_OfferAcceptedEvent(object sender, EventArgs e)
        {
            if (sender == AiChannel)
            {
                Status.LastAcceptedOffer = Status.HumanStatus.Offer;
            }
            else
            {
                Status.LastAcceptedOffer = Status.AiStatus.Offer;
            }

            Status.AiStatus.Signed    = false;
            Status.HumanStatus.Signed = false;

            Status.AcceptedOfferSide = (INegotiationChannel)sender;

            SideConfig side = (Status.AcceptedOfferSide == AiChannel) ? AiConfig : HumanConfig;

            this.Actions.Add(new NegotiationActionModel()
            {
                RemainingTime = Status.RemainingTime,
                Role          = side.Side,
                Type          = NegotiationActionType.AcceptOffer
            });

            NegotiationManager.SaveOfferAccepted(this, side);

            ThreadPool.QueueUserWorkItem(x =>
            {
                GetOtherChannel(Status.AcceptedOfferSide).OpponentAcceptedOffer();
            });
        }
示例#2
0
        public void Initialize(NegotiationDomain domain, SideConfig strategyConfig, String opponentSide, INegotiationClient client)
        {
            Client = client;

            client.OfferReceivedEvent += client_OfferReceivedEvent;
            client.NegotiationEndedEvent += client_NegotiationEndedEvent;
        }
示例#3
0
        public override void Initialize(Negotiation.Models.NegotiationDomain domain, Negotiation.Models.SideConfig strategyConfig, string opponentSide, Negotiation.Models.INegotiationClient client)
        {
            base.Initialize(domain, strategyConfig, opponentSide, client);

            m_BestCombinedUtilityOffers = new Dictionary <string, OfferUtility>(BestCombinedUtilityOffers);
            m_BestFScoreUtilityOffers   = new Dictionary <string, OfferUtility>(BestFScoreUtilityOffers);

            m_typeUtilities = Domain.OwnerVariantDict[OpponentSide].Keys.ToDictionary(k => k, k => 0.0);
        }
示例#4
0
        public virtual void Initialize(NegotiationDomain domain, SideConfig strategyConfig, String opponentSide, INegotiationClient client)
        {
            Domain = domain;
            StrategyConfig = strategyConfig;
            Client = client;
            OpponentSide = opponentSide;

            Client.NegotiationStartedEvent += OnNegotiationStartedEvent;
            Client.NegotiationEndedEvent += OnNegotiationEndedEvent;
            Client.OfferReceivedEvent += OnOfferReceivedEventInner;
            Client.TimePassedEvent += OnTimePassedEventInner;
            Client.OpponentAcceptedOfferEvent += OnOpponentAcceptedOfferEvent;

            CalculateOffers();
        }
示例#5
0
        public override void Initialize(Negotiation.Models.NegotiationDomain domain, Negotiation.Models.SideConfig strategyConfig, string opponentSide, Negotiation.Models.INegotiationClient client)
        {
            base.Initialize(domain, strategyConfig, opponentSide, client);

            m_BestCombinedUtilityOffers = new Dictionary <string, OfferUtility>(BestCombinedUtilityOffers);
            m_BestFScoreUtilityOffers   = new Dictionary <string, OfferUtility>(BestFScoreUtilityOffers);

            var opponentTypes = domain.OwnerVariantDict[opponentSide].Keys;

            m_typeProbabilites = opponentTypes.ToDictionary(k => k, x => (1.0 / opponentTypes.Count));

            var utilitySums = opponentTypes.ToDictionary(k => k, k => AllOptions.Values.Sum(x => x.UtilityDataDict[k].OpponentUtility));

            m_offerProbabilities = AllOptions.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.UtilityDataDict.ToDictionary(kvp2 => kvp2.Key, kvp2 => kvp2.Value.OpponentUtility / utilitySums[kvp2.Key]));
        }
示例#6
0
        private static void SaveAction(NegotiationEngine engine, SideConfig side, NegotiationActionType type, String value = "")
        {
            NegotiationContainer cont = new NegotiationContainer();

            var game = cont.GameSet.Find(engine.NegotiationId);
            var user = game.Users.First(x => x.Type == side.Type);

            cont.NegotiationActionSet.Add(new NegotiationAction()
            {
                GameId        = engine.NegotiationId,
                Type          = type,
                User          = user,
                RemainingTime = engine.Status.RemainingTime,
                UserId        = user.Id,
                Value         = value
            });
            cont.SaveChanges();
        }
示例#7
0
        void channel_OfferRejectedEvent(object sender, EventArgs e)
        {
            SideConfig side = (sender == AiChannel) ? AiConfig : HumanConfig;

            this.Actions.Add(new NegotiationActionModel()
            {
                RemainingTime = Status.RemainingTime,
                Role          = side.Side,
                Type          = NegotiationActionType.RejectOffer
            });

            NegotiationManager.SaveOfferRejected(this, side);

            ThreadPool.QueueUserWorkItem(x =>
            {
                GetOtherChannel((INegotiationChannel)sender).OpponentRejectedOffer();
            });
        }
示例#8
0
        public NegotiationEngine(
            String negotiationId,
            NegotiationDomain domain,
            PreNegotiationQuestionnaireViewModel userData,
            SideConfig humanConfig,
            AiConfig aiConfig)
        {
            NegotiationId = negotiationId;
            Domain        = domain;
            HumanChannel  = new LocalNegotiationChannel();
            AiChannel     = new LocalNegotiationChannel();
            HumanConfig   = humanConfig;
            AiConfig      = aiConfig;

            Status = new NegotiationStatus()
            {
                RemainingTime = TimeSpan.FromSeconds(domain.NumberOfRounds * domain.RoundLength.TotalSeconds),
                HumanStatus   = new SideStatus()
                {
                    Offer = EmptyOffer()
                },
                AiStatus = new SideStatus()
                {
                    Offer = EmptyOffer()
                },
                LastAcceptedOffer = EmptyOffer()
            };

            Actions = new List <NegotiationActionModel>();

            String         strategyName;
            IAgentStrategy strat = NegotiationManager.GetStrategy(aiConfig.StrategyId, out strategyName);

            strat.Initialize(domain, aiConfig, humanConfig.Side, AiChannel);

            TimeSpan defaultInterval = TimeSpan.FromSeconds(1);

            UpdateInterval = defaultInterval < strat.MinimumUpdateTime ? defaultInterval : strat.MinimumUpdateTime;

            StrategyName = strategyName;

            RegisterChannel(HumanChannel);
            RegisterChannel(AiChannel);
        }
        private static void SaveAction(NegotiationEngine engine, SideConfig side, NegotiationActionType type, String value = "")
        {
            NegotiationContainer cont = new NegotiationContainer();

            var game = cont.GameSet.Find(engine.NegotiationId);
            var user = game.Users.First(x => x.Type == side.Type);

            cont.NegotiationActionSet.Add(new NegotiationAction()
            {
                GameId = engine.NegotiationId,
                Type = type,
                User = user,
                RemainingTime = engine.Status.RemainingTime,
                UserId = user.Id,
                Value = value
            });
            cont.SaveChanges();
        }
示例#10
0
 public NegotiationSideDescription GetSideDescription(SideConfig config)
 {
     return OwnerVariantDict[config.Side][config.Variant];
 }
示例#11
0
 internal static void SaveOfferRejected(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.RejectOffer);
 }
示例#12
0
 internal static void SaveOptOut(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Optout);
 }
示例#13
0
 internal static void SaveAgreementSigned(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Sign);
 }
示例#14
0
 internal static void SaveNewOffer(NegotiationEngine engine, SideConfig side, string negotiationOffer)
 {
     SaveAction(engine, side, NegotiationActionType.MakeOffer, negotiationOffer);
 }
示例#15
0
 internal static void SaveNewOffer(NegotiationEngine engine, SideConfig side, string negotiationOffer)
 {
     SaveAction(engine, side, NegotiationActionType.MakeOffer, negotiationOffer);
 }
示例#16
0
 internal static void SaveOfferRejected(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.RejectOffer);
 }
示例#17
0
 public int CalculateOptoutScore(SideConfig config, int roundsPassed)
 {
     var variant = OwnerVariantDict[config.Side][config.Variant];
     return variant.Optout + variant.TimeEffect * roundsPassed;
 }
示例#18
0
        public int CalculateOptoutScore(SideConfig config, int roundsPassed)
        {
            var variant = OwnerVariantDict[config.Side][config.Variant];

            return(variant.Optout + variant.TimeEffect * roundsPassed);
        }
示例#19
0
        private int CalculateAcceptScore(SideConfig config, NegotiationOffer offer)
        {
            var variant = Domain.OwnerVariantDict[config.Side][config.Variant];

            return(offer.Offers.Sum(x => variant.Topics[x.Key].Options[x.Value].Score) + variant.TimeEffect * Domain.RoundsPassed(Status.RemainingTime));
        }
示例#20
0
 public NegotiationSideDescription GetSideDescription(SideConfig config)
 {
     return(OwnerVariantDict[config.Side][config.Variant]);
 }
示例#21
0
 internal static void SaveOptOut(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Optout);
 }
示例#22
0
 public int CalculateTimeoutScore(SideConfig config)
 {
     var variant = OwnerVariantDict[config.Side][config.Variant];
     return variant.Reservation + variant.TimeEffect * NumberOfRounds;
 }
示例#23
0
 protected double CalculateUtility(IEnumerable<KeyValuePair<String, String>> offer, SideConfig config)
 {
     var sideDesc = Domain.GetSideDescription(config);
     return offer.Aggregate(0.0, (sum, x) => sum + sideDesc.Topics[x.Key].Options[x.Value].Score);
 }
示例#24
0
        public int CalculateTimeoutScore(SideConfig config)
        {
            var variant = OwnerVariantDict[config.Side][config.Variant];

            return(variant.Reservation + variant.TimeEffect * NumberOfRounds);
        }
示例#25
0
 internal static void SaveAgreementSigned(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Sign);
 }
示例#26
0
 public int CalculateOptoutScore(SideConfig config, TimeSpan remainingTime)
 {
     return(CalculateOptoutScore(config, RoundsPassed(remainingTime)));
 }
示例#27
0
 public int CalculateOptoutScore(SideConfig config, TimeSpan remainingTime)
 {
     return CalculateOptoutScore(config, RoundsPassed(remainingTime));
 }