Exemplo n.º 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();
            });
        }
Exemplo n.º 2
0
        public void Initialize(NegotiationDomain domain, SideConfig strategyConfig, String opponentSide, INegotiationClient client)
        {
            Client = client;

            client.OfferReceivedEvent += client_OfferReceivedEvent;
            client.NegotiationEndedEvent += client_NegotiationEndedEvent;
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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]));
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
            });
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
 public NegotiationSideDescription GetSideDescription(SideConfig config)
 {
     return OwnerVariantDict[config.Side][config.Variant];
 }
Exemplo n.º 11
0
 internal static void SaveOfferRejected(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.RejectOffer);
 }
Exemplo n.º 12
0
 internal static void SaveOptOut(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Optout);
 }
Exemplo n.º 13
0
 internal static void SaveAgreementSigned(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Sign);
 }
Exemplo n.º 14
0
 internal static void SaveNewOffer(NegotiationEngine engine, SideConfig side, string negotiationOffer)
 {
     SaveAction(engine, side, NegotiationActionType.MakeOffer, negotiationOffer);
 }
Exemplo n.º 15
0
 internal static void SaveNewOffer(NegotiationEngine engine, SideConfig side, string negotiationOffer)
 {
     SaveAction(engine, side, NegotiationActionType.MakeOffer, negotiationOffer);
 }
Exemplo n.º 16
0
 internal static void SaveOfferRejected(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.RejectOffer);
 }
Exemplo n.º 17
0
 public int CalculateOptoutScore(SideConfig config, int roundsPassed)
 {
     var variant = OwnerVariantDict[config.Side][config.Variant];
     return variant.Optout + variant.TimeEffect * roundsPassed;
 }
Exemplo n.º 18
0
        public int CalculateOptoutScore(SideConfig config, int roundsPassed)
        {
            var variant = OwnerVariantDict[config.Side][config.Variant];

            return(variant.Optout + variant.TimeEffect * roundsPassed);
        }
Exemplo n.º 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));
        }
Exemplo n.º 20
0
 public NegotiationSideDescription GetSideDescription(SideConfig config)
 {
     return(OwnerVariantDict[config.Side][config.Variant]);
 }
Exemplo n.º 21
0
 internal static void SaveOptOut(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Optout);
 }
Exemplo n.º 22
0
 public int CalculateTimeoutScore(SideConfig config)
 {
     var variant = OwnerVariantDict[config.Side][config.Variant];
     return variant.Reservation + variant.TimeEffect * NumberOfRounds;
 }
Exemplo n.º 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);
 }
Exemplo n.º 24
0
        public int CalculateTimeoutScore(SideConfig config)
        {
            var variant = OwnerVariantDict[config.Side][config.Variant];

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