Exemple #1
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);
        }
        internal static void SaveNewNegotiation(NegotiationEngine engine, PreNegotiationQuestionnaireViewModel model)
        {
            NegotiationContainer cont = new NegotiationContainer();

            #region Human User
            UserRole humanRole = new UserRole()
            {
                Description = engine.HumanConfig.Side,
                Variant = engine.HumanConfig.Variant
            };

            UserData humanData = new UserData()
            {
                AgeRange = model.AgeRange,
                Country = model.BirthCountry,
                DegreeField = model.DegreeField,
                Education = model.Education,
                Gender = model.Gender,
                StudentId = model.ID,
                Name = model.Name,
                University = model.University
            };

            User humanUser = new User()
            {
                Id = engine.NegotiationId,
                Type = UserType.Human,
                UserData = humanData,
                UserRole = humanRole,
                GameId = engine.NegotiationId
            };

            #endregion

            #region Ai User

            UserRole aiRole = new UserRole()
            {
                Description = engine.AiConfig.Side,
                Variant = engine.AiConfig.Variant
            };

            User aiUser = new User()
            {
                Id = engine.StrategyName + "|" + DateTime.Now,
                Type = UserType.Agent,
                StrategyId = engine.AiConfig.StrategyId,
                UserRole = aiRole,
                GameId = engine.NegotiationId,
            };

            #endregion

            cont.GameSet.Add(new Game()
                {
                    Id = engine.NegotiationId,
                    GameDomainId = GameDomain.Id,
                    StartTime = DateTime.Now
                });

            cont.UserDataSet.Add(humanData);
            cont.UserRoleSet.Add(humanRole);
            cont.UserRoleSet.Add(aiRole);
            cont.UserSet.Add(humanUser);
            cont.UserSet.Add(aiUser);

            try
            {
                cont.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
        public ActionResult SubmitUserData(PreNegotiationQuestionnaireViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View("PreNegotiationQuestionnaire", model);
            }

            if (!model.AgreeIRB)
            {
                ModelState.AddModelError("AgreeIRB", "Please agree to the IRB form");
                return View("PreNegotiationQuestionnaire", model);
            }

            String id = CreateNewNegotiation(model);

            NegotiationTutorialModel tutModel = CreateTutorialModel(id);
            NegotiationManager.TutorialModels.TryAdd(id, tutModel);

            return NegotiationTutorial(tutModel);
        }
        private string CreateNewNegotiation(PreNegotiationQuestionnaireViewModel model)
        {
            string id = this.Request.UserHostAddress + ";" + DateTime.Now.ToUniversalTime().ToString(CultureInfo.InvariantCulture);
            NegotiationEngine engine =
                new NegotiationEngine(
                    id,
                    NegotiationManager.Domain,
                    model,
                    NegotiationManager.GetHumanConfig(),
                    NegotiationManager.GetAiConfig());

            NegotiationManager.SaveNewNegotiation(engine, model);
            NegotiationManager.OnGoingNegotiations.TryAdd(id, engine);

            return id;
        }
Exemple #5
0
        internal static void SaveNewNegotiation(NegotiationEngine engine, PreNegotiationQuestionnaireViewModel model)
        {
            NegotiationContainer cont = new NegotiationContainer();

            #region Human User
            UserRole humanRole = new UserRole()
            {
                Description = engine.HumanConfig.Side,
                Variant     = engine.HumanConfig.Variant
            };

            UserData humanData = new UserData()
            {
                AgeRange    = model.AgeRange,
                Country     = model.BirthCountry,
                DegreeField = model.DegreeField,
                Education   = model.Education,
                Gender      = model.Gender,
                StudentId   = model.ID,
                Name        = model.Name,
                University  = model.University
            };

            User humanUser = new User()
            {
                Id       = engine.NegotiationId,
                Type     = UserType.Human,
                UserData = humanData,
                UserRole = humanRole,
                GameId   = engine.NegotiationId
            };

            #endregion

            #region Ai User

            UserRole aiRole = new UserRole()
            {
                Description = engine.AiConfig.Side,
                Variant     = engine.AiConfig.Variant
            };

            User aiUser = new User()
            {
                Id         = engine.StrategyName + "|" + DateTime.Now,
                Type       = UserType.Agent,
                StrategyId = engine.AiConfig.StrategyId,
                UserRole   = aiRole,
                GameId     = engine.NegotiationId,
            };

            #endregion

            cont.GameSet.Add(new Game()
            {
                Id           = engine.NegotiationId,
                GameDomainId = GameDomain.Id,
                StartTime    = DateTime.Now
            });

            cont.UserDataSet.Add(humanData);
            cont.UserRoleSet.Add(humanRole);
            cont.UserRoleSet.Add(aiRole);
            cont.UserSet.Add(humanUser);
            cont.UserSet.Add(aiUser);

            try
            {
                cont.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }