Ejemplo n.º 1
0
 public static void AddCompanies(this IPlanner planner, params IReadOnlyTravelCompany[] companies)
 {
     foreach (var company in companies)
     {
         planner.AddTravelCompany(company);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadOnlyKernel"/> class.
        /// </summary>
        /// <param name="settings">The <see cref="INinjectSettings"/>.</param>
        /// <param name="bindings">The preconfigured bindings.</param>
        /// <param name="cache">The <see cref="ICache"/> component.</param>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
        /// <param name="pipeline">The <see cref="IPipeline"/> component.</param>
        /// <param name="exceptionFormatter">The <see cref="IExceptionFormatter"/> component.</param>
        /// <param name="bindingPrecedenceComparer">The <see cref="IBindingPrecedenceComparer"/> component.</param>
        /// <param name="bindingResolvers">The binding resolvers.</param>
        /// <param name="missingBindingResolvers">The missing binding resolvers.</param>
        internal ReadOnlyKernel(
            INinjectSettings settings,
            Dictionary <Type, ICollection <IBinding> > bindings,
            ICache cache,
            IPlanner planner,
            IConstructorScorer constructorScorer,
            IPipeline pipeline,
            IExceptionFormatter exceptionFormatter,
            IBindingPrecedenceComparer bindingPrecedenceComparer,
            List <IBindingResolver> bindingResolvers,
            List <IMissingBindingResolver> missingBindingResolvers)
        {
            this.settings                = settings;
            this.bindings                = bindings;
            this.bindingResolvers        = bindingResolvers;
            this.missingBindingResolvers = missingBindingResolvers;
            this.cache                     = cache;
            this.planner                   = planner;
            this.constructorScorer         = constructorScorer;
            this.pipeline                  = pipeline;
            this.exceptionFormatter        = exceptionFormatter;
            this.bindingPrecedenceComparer = bindingPrecedenceComparer;

            this.AddReadOnlyKernelBinding <IReadOnlyKernel>(this, bindings);
            this.AddReadOnlyKernelBinding <IResolutionRoot>(this, bindings);
        }
Ejemplo n.º 3
0
 public StreamJob(IStreamSender sender, IPlanner planner, ILog log, TimeSpan requestTimeout)
 {
     this.log            = log;
     this.sender         = sender;
     this.planner        = planner;
     this.requestTimeout = requestTimeout;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadOnlyKernel"/> class.
        /// </summary>
        /// <param name="bindings">The preconfigured bindings</param>
        /// <param name="cache">Dependency injection for <see cref="ICache"/></param>
        /// <param name="planner">Dependency injection for <see cref="IPlanner"/></param>
        /// <param name="pipeline">Dependency injection for <see cref="IPipeline"/></param>
        /// <param name="bindingPrecedenceComparer">Dependency injection for <see cref="IBindingPrecedenceComparer"/></param>
        /// <param name="bindingResolvers">Dependency injection for all binding resolvers</param>
        /// <param name="missingBindingResolvers">Dependency injection for all missng binding resolvers</param>
        /// <param name="settings">Dependency injection for for <see cref="INinjectSettings"/></param>
        /// <param name="selector">Dependency injection for <see cref="ISelector"/></param>
        public ReadOnlyKernel(
            Multimap <Type, IBinding> bindings,
            ICache cache,
            IPlanner planner,
            IPipeline pipeline,
            IBindingPrecedenceComparer bindingPrecedenceComparer,
            IEnumerable <IBindingResolver> bindingResolvers,
            IEnumerable <IMissingBindingResolver> missingBindingResolvers,
            INinjectSettings settings,
            ISelector selector)
        {
            this.bindingResolvers        = bindingResolvers;
            this.missingBindingResolvers = missingBindingResolvers;
            this.cache    = cache;
            this.planner  = planner;
            this.pipeline = pipeline;
            this.bindingPrecedenceComparer = bindingPrecedenceComparer;
            this.Settings = settings;

            this.AddReadOnlyKernelBinding <IReadOnlyKernel>(this, bindings);
            this.AddReadOnlyKernelBinding <IResolutionRoot>(this, bindings);

            this.bindings = bindings.Keys.ToDictionary(type => type, type => bindings[type]);
            this.InitializeBindings(selector);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadOnlyKernel"/> class.
        /// </summary>
        /// <param name="bindings">The preconfigured bindings.</param>
        /// <param name="cache">The <see cref="ICache"/> component.</param>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="scorer">The <see cref="IConstructorScorer"/> component.</param>
        /// <param name="pipeline">The <see cref="IPipeline"/> component.</param>
        /// <param name="bindingPrecedenceComparer">The <see cref="IBindingPrecedenceComparer"/> component.</param>
        /// <param name="bindingResolvers">The binding resolvers.</param>
        /// <param name="missingBindingResolvers">The missng binding resolvers.</param>
        /// <param name="settings">The <see cref="INinjectSettings"/>.</param>
        internal ReadOnlyKernel(
            INinjectSettings settings,
            IDictionary <Type, ICollection <IBinding> > bindings,
            ICache cache,
            IPlanner planner,
            IConstructorScorer scorer,
            IPipeline pipeline,
            IBindingPrecedenceComparer bindingPrecedenceComparer,
            IEnumerable <IBindingResolver> bindingResolvers,
            IEnumerable <IMissingBindingResolver> missingBindingResolvers)
        {
            this.Settings = settings;

            this.bindingResolvers        = bindingResolvers;
            this.missingBindingResolvers = missingBindingResolvers;
            this.cache    = cache;
            this.planner  = planner;
            this.scorer   = scorer;
            this.pipeline = pipeline;
            this.bindingPrecedenceComparer = bindingPrecedenceComparer;

            this.AddReadOnlyKernelBinding <IReadOnlyKernel>(this, bindings);
            this.AddReadOnlyKernelBinding <IResolutionRoot>(this, bindings);

            this.bindings = bindings.Keys.ToDictionary(type => type, type => bindings[type]);
            this.InitializeBindings();
        }
Ejemplo n.º 6
0
 // コンストラクタ
 public Brain(T owner) : base(owner)
 {
     // NOTE:
     // 他キャラのAIを作成する場合はBrainの派生クラスを作成し、
     // そちらのコンストラクタ内で、生成するプランナーを変更する
     _planner = new CharaPlanner(owner);
 }
Ejemplo n.º 7
0
        public static async Task <Agent> Create(IConfigSource configSource, IPlanner planner, IPlanRunner planRunner, IReporter reporter,
                                                IModuleIdentityLifecycleManager moduleIdentityLifecycleManager, IEnvironmentProvider environmentProvider,
                                                IEntityStore <string, string> configStore, ISerde <DeploymentConfigInfo> deploymentConfigInfoSerde, IEncryptionProvider encryptionProvider)
        {
            Preconditions.CheckNotNull(deploymentConfigInfoSerde, nameof(deploymentConfigInfoSerde));
            Preconditions.CheckNotNull(configStore, nameof(configStore));

            Option <DeploymentConfigInfo> deploymentConfigInfo = Option.None <DeploymentConfigInfo>();

            try
            {
                Option <string> deploymentConfigInfoJson = await Preconditions.CheckNotNull(configStore, nameof(configStore)).Get(StoreConfigKey);

                await deploymentConfigInfoJson.ForEachAsync(async json =>
                {
                    string decryptedJson = await encryptionProvider.DecryptAsync(json);
                    deploymentConfigInfo = Option.Some(deploymentConfigInfoSerde.Deserialize(decryptedJson));
                });
            }
            catch (Exception ex) when(!ex.IsFatal())
            {
                Events.ErrorDeserializingConfig(ex);
            }
            var agent = new Agent(configSource, environmentProvider, planner, planRunner, reporter, moduleIdentityLifecycleManager,
                                  configStore, deploymentConfigInfo.GetOrElse(DeploymentConfigInfo.Empty), deploymentConfigInfoSerde, encryptionProvider);

            return(agent);
        }
Ejemplo n.º 8
0
 public Agent(
     IConfigSource configSource,
     IEnvironmentProvider environmentProvider,
     IPlanner planner,
     IPlanRunner planRunner,
     IReporter reporter,
     IModuleIdentityLifecycleManager moduleIdentityLifecycleManager,
     IEntityStore <string, string> configStore,
     DeploymentConfigInfo initialDeployedConfigInfo,
     ISerde <DeploymentConfigInfo> deploymentConfigInfoSerde,
     IEncryptionProvider encryptionProvider,
     IAvailabilityMetric availabilityMetric)
 {
     this.configSource = Preconditions.CheckNotNull(configSource, nameof(configSource));
     this.planner      = Preconditions.CheckNotNull(planner, nameof(planner));
     this.planRunner   = Preconditions.CheckNotNull(planRunner, nameof(planRunner));
     this.reporter     = Preconditions.CheckNotNull(reporter, nameof(reporter));
     this.moduleIdentityLifecycleManager = Preconditions.CheckNotNull(moduleIdentityLifecycleManager, nameof(moduleIdentityLifecycleManager));
     this.configStore               = Preconditions.CheckNotNull(configStore, nameof(configStore));
     this.environmentProvider       = Preconditions.CheckNotNull(environmentProvider, nameof(environmentProvider));
     this.currentConfig             = Preconditions.CheckNotNull(initialDeployedConfigInfo);
     this.deploymentConfigInfoSerde = Preconditions.CheckNotNull(deploymentConfigInfoSerde, nameof(deploymentConfigInfoSerde));
     this.environment               = this.environmentProvider.Create(this.currentConfig.DeploymentConfig);
     this.encryptionProvider        = Preconditions.CheckNotNull(encryptionProvider, nameof(encryptionProvider));
     this.availabilityMetric        = Preconditions.CheckNotNull(availabilityMetric, nameof(availabilityMetric));
     this.status = DeploymentStatus.Unknown;
     Events.AgentCreated();
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelfBindingResolver"/> class.
        /// </summary>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="scorer">The <see cref="IConstructorScorer"/> component.</param>
        public SelfBindingResolver(IPlanner planner, IConstructorScorer scorer)
        {
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(scorer, "scorer");

            this.planner = planner;
            this.scorer  = scorer;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="planner">The planner component.</param>
        public StandardProvider(Type type, IPlanner planner)
        {
            Ensure.ArgumentNotNull(type, "type");
            Ensure.ArgumentNotNull(planner, "planner");

            Type = type;
            Planner = planner;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets a callback that creates an instance of the <see cref="StandardProvider"/>
        /// for the specified type.
        /// </summary>
        /// <param name="prototype">The prototype the provider instance will create.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="scorer">The constructor scorer.</param>
        /// <returns>The created callback.</returns>
        public static Func <IContext, IProvider> GetCreationCallback(Type prototype, IPlanner planner, IConstructorScorer scorer)
        {
            Ensure.ArgumentNotNull(prototype, "prototype");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(scorer, "scorer");

            return(ctx => new StandardProvider(prototype, planner, scorer));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets a callback that creates an instance of the <see cref="StandardProvider"/>
        /// for the specified type and constructor.
        /// </summary>
        /// <param name="prototype">The prototype the provider instance will create.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="constructor">The constructor.</param>
        /// <returns>The created callback.</returns>
        public static Func <IContext, IProvider> GetCreationCallback(Type prototype, IPlanner planner, ConstructorInfo constructor)
        {
            Ensure.ArgumentNotNull(prototype, "prototype");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(constructor, "constructor");

            return(GetCreationCallback(prototype, planner, new SpecificConstructorSelector(constructor)));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelfBindingResolver"/> class.
        /// </summary>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
        public SelfBindingResolver(IPlanner planner, IConstructorScorer constructorScorer)
        {
            Ensure.ArgumentNotNull(planner, nameof(planner));
            Ensure.ArgumentNotNull(constructorScorer, nameof(constructorScorer));

            this.planner           = planner;
            this.constructorScorer = constructorScorer;
        }
Ejemplo n.º 14
0
        public List <IPlan> Search(IPlanner IP, int k, float cutoff)
        {
            var Solutions = new List <IPlan>();

            var watch = System.Diagnostics.Stopwatch.StartNew();

            while (Frontier.Count > 0)
            {
                var plan = Frontier.Dequeue();
                IP.Expanded++;
                var flaw = plan.Flaws.Next();
                Console.WriteLine(plan.Decomps);
                if (IP.Console_log)
                {
                    Console.WriteLine(plan.ToStringOrdered());
                    Console.WriteLine(flaw);
                }

                // Termination criteria
                if (flaw == null)
                {
                    watch.Stop();
                    var elapsedMs = watch.ElapsedMilliseconds;

                    Solutions.Add(plan);
                    if (Solutions.Count >= k)
                    {
                        IP.WriteToFile(elapsedMs, plan as Plan);

                        return(Solutions);
                    }
                    continue;
                }

                if (watch.ElapsedMilliseconds > cutoff)
                {
                    watch.Stop();
                    IP.WriteToFile(watch.ElapsedMilliseconds, plan as Plan);
                    return(null);
                }

                var frontierCount = Frontier.Count;

                if (flaw.Ftype == Enums.FlawType.Link)
                {
                    IP.RepairThreat(plan, flaw as ThreatenedLinkFlaw);
                }

                else if (flaw.Ftype == Enums.FlawType.Condition)
                {
                    IP.AddStep(plan, flaw as OpenCondition);
                    IP.Reuse(plan, flaw as OpenCondition);
                }
            }

            return(null);
        }
Ejemplo n.º 15
0
 public Performer(IAgent <TAction, TGoal> agent)
 {
     _planHandler = new PlanHandler <TAction>();
     _planHandler.AddCompleteCallBack(PlanComplete);
     _planner       = new Planner <TAction, TGoal>(agent);
     _goalManager   = agent.GoalManager;
     _actionManager = agent.ActionManager;
     _actionManager.AddActionCompleteListener(PlanActionComplete);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="selector">The selector component.</param>
        public StandardProvider(Type type, IPlanner planner, ISelector selector)
        {
            Ensure.ArgumentNotNull(type, "type");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(selector, "selector");

            Type     = type;
            Planner  = planner;
            Selector = selector;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="constructorScorer">The constructor scorer component.</param>
        public StandardProvider(Type type, IPlanner planner, IConstructorScorer constructorScorer)
        {
            Ensure.ArgumentNotNull(type, "type");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");

            this.Type              = type;
            this.Planner           = planner;
            this.ConstructorScorer = constructorScorer;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="selector">The selector component.</param>
        public StandardProvider(Type type, IPlanner planner, ISelector selector)
        {
            Ensure.ArgumentNotNull(type, "type");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(selector, "selector");

            Type = type;
            Planner = planner;
            Selector = selector;
        }
Ejemplo n.º 19
0
        public void Constructor_ShouldThrowArgumentNullExceptionWhenPlannerIsNull()
        {
            var            type              = typeof(Monk);
            const IPlanner planner           = null;
            var            constructorScorer = _constructorScorerMock.Object;

            var actual = Assert.Throws <ArgumentNullException>(() => new StandardProvider(type, planner, constructorScorer));

            Assert.Null(actual.InnerException);
            Assert.Equal(nameof(planner), actual.ParamName);
        }
        public EducationPlanManager(string profilePath, ICourseService courseService, string managementPropertiesPath, string educationPlanPath, string educationPlanUpdatedPath, string modulePath)
        {
            _courseService = courseService;
            IManagementPropertiesDataMapper managementPropertiesDataMapper = new ManagementPropertiesJsonDataMapper(managementPropertiesPath);

            _planner = new Planner(managementPropertiesDataMapper);
            _educationPlanOutputter  = new EducationPlanOutputter(_planner, managementPropertiesDataMapper);
            _profileDataMapper       = new ProfileJsonDataMapper(profilePath);
            _educationPlanDataMapper = new EducationPlanJsonDataMapper(educationPlanPath, educationPlanUpdatedPath);
            _moduleDataMapper        = new ModuleJSONDataMapper(modulePath);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="constructorScorer">The constructor scorer component.</param>
        public StandardProvider(Type type, IPlanner planner, IConstructorScorer constructorScorer
            )
        {
            Ensure.ArgumentNotNull(type, "type");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");

            Type = type;
            Planner = planner;
            ConstructorScorer = constructorScorer;
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Requires 3 arguments: SOCKET SIM_ID PROBLEM");
                return;
            }
            var socketAddr = args[0];
            var identity   = new UTF8Encoding().GetBytes(args[1]);
            //IPlanner planner = args[2] == "HS" ? new HotStorage.Planner() : new RollingMill.Planner();
            IPlanner planner = args[2] == "HS" ? new csharp.HS_Sync.SyncHSPlanner() : new RollingMill.Planner();

            OptimizerType optType;

            if (args.Length > 2)
            {
                optType = OptimizerType.RuleBased;
            }
            else
            {
                optType = OptimizerType.ModelBased;
            }

            Console.WriteLine(optType);

            using (var socket = new DealerSocket()) {
                socket.Options.Identity = identity;
                socket.Connect(socketAddr);
                Console.WriteLine("Connected");

                while (true)
                {
                    Console.WriteLine("Waiting for request...");
                    var request = socket.ReceiveMultipartBytes();
                    Console.WriteLine("Incoming request");
                    var answer = planner.PlanMoves(request[2], optType);

                    var msg = new NetMQMessage();
                    msg.AppendEmptyFrame();
                    msg.Append("crane");
                    if (answer != null)
                    {
                        msg.Append(answer);
                    }
                    else
                    {
                        msg.AppendEmptyFrame();
                    }

                    socket.SendMultipartMessage(msg);
                }
            }
        }
 public EducationPlanManager(ICourseService courseService, IPlanner planner, IEducationPlanOutputter educationPlanOutputter,
                             IDataMapper <OpleidingsplanGenerator.Models.CourseProfile> profileDataMapper, IEducationPlanDataMapper educationPlanDataMapper,
                             IEducationPlanConverter educationPlanConverter, IDataMapper <Module> moduleDataMapper)
 {
     _courseService           = courseService;
     _planner                 = planner;
     _educationPlanOutputter  = educationPlanOutputter;
     _profileDataMapper       = profileDataMapper;
     _educationPlanDataMapper = educationPlanDataMapper;
     _educationPlanConverter  = educationPlanConverter;
     _moduleDataMapper        = moduleDataMapper;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindingBuilder{T1, T2, T3, T4}"/> class.
 /// </summary>
 /// <param name="bindingConfiguration">The binding to build.</param>
 /// <param name="planner">The <see cref="IPlanner"/> component.</param>
 /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
 /// <param name="serviceNames">The names of the services.</param>
 /// <exception cref="ArgumentNullException"><paramref name="bindingConfiguration"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="planner"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="constructorScorer"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="serviceNames"/> is <see langword="null"/>.</exception>
 public BindingBuilder(
     IBindingConfiguration bindingConfiguration,
     IPlanner planner,
     IConstructorScorer constructorScorer,
     string serviceNames)
     : base(
         bindingConfiguration,
         planner,
         constructorScorer,
         serviceNames)
 {
 }
Ejemplo n.º 25
0
        public virtual void Awake()
        {
            _game      = FindObjectOfType <Game>();
            _planner   = new NormalPlanner();
            _available = new HashSet <GOAPAction>();
            _actions   = new Queue <GOAPAction>();
            _useable   = new List <GOAPAction>();

            _created = DateTime.Now;

            _world = new Dictionary <string, object>();
            _goal  = new Dictionary <string, object>();
        }
Ejemplo n.º 26
0
        // etc.

        public AgentEnvironment(
            IGoalSelector goalSelector,
            IPlanner planner,
            IKnowledgeProvider knowledgeProvider,
            IPlanExecutor planExecutor,
            IReevaluationSensor reevaluationSensor = null
            )
        {
            this.GoalSelector       = PreconditionUtils.EnsureNotNull(goalSelector, "goalSelector");
            this.Planner            = PreconditionUtils.EnsureNotNull(planner, "planner");
            this.KnowledgeProvider  = PreconditionUtils.EnsureNotNull(knowledgeProvider, "knowledgeProvider");
            this.PlanExecutor       = PreconditionUtils.EnsureNotNull(planExecutor, "planExecutor");
            this.ReevaluationSensor = reevaluationSensor != null ? reevaluationSensor : new NullReevaluationSensor();
        }
Ejemplo n.º 27
0
 private AgentConfiguration(
     IGoalSelector goalSelector,
     IPlanner planner,
     IKnowledgeProvider knowledgeProvider,
     IPlanExecutor planExecutor,
     IReevaluationSensor reevaluationSensor = null
     )
 {
     GoalSelector       = PreconditionUtils.EnsureNotNull(goalSelector, "goalSelector");
     Planner            = PreconditionUtils.EnsureNotNull(planner, "planner");
     KnowledgeProvider  = PreconditionUtils.EnsureNotNull(knowledgeProvider, "knowledgeProvider");
     PlanExecutor       = PreconditionUtils.EnsureNotNull(planExecutor, "planExecutor");
     ReevaluationSensor = reevaluationSensor ?? new NullReevaluationSensor();
 }
Ejemplo n.º 28
0
 public Executor(IJobRepository jobRepository, ISemaphoreRepository semaphoreRepository, ICommandRepository commandRepository, IPlanner planner, ITimeProvider timeProvider, IEnumerable <IPlugin> plugins, ICallbackService callbackService, ILogging logging)
 {
     _jobRepository       = jobRepository;
     _semaphoreRepository = semaphoreRepository;
     _commandRepository   = commandRepository;
     _callbackService     = callbackService;
     _planner             = planner;
     _timeProvider        = timeProvider;
     _plugins             = plugins.ToList();
     _logging             = logging;
     if (_plugins.Select(p => p.Urn).Distinct().Count() != _plugins.Count())
     {
         throw new ArgumentException("Invalid plugin configuration, not unique urns detected", nameof(plugins));
     }
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindingBuilder{T1}"/> class.
        /// </summary>
        /// <param name="binding">The binding to build.</param>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
        /// <param name="serviceNames">The names of the services.</param>
        public BindingBuilder(
            IBinding binding,
            IPlanner planner,
            IConstructorScorer constructorScorer,
            string serviceNames)
            : base(
                binding.BindingConfiguration,
                planner,
                constructorScorer,
                serviceNames)
        {
            Ensure.ArgumentNotNull(binding, "binding");

            this.Binding = binding;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindingBuilder"/> class.
        /// </summary>
        /// <param name="bindingConfiguration">The binding to build.</param>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
        /// <param name="serviceNames">The names of the services.</param>
        /// <exception cref="ArgumentNullException"><paramref name="bindingConfiguration"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="planner"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="constructorScorer"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="serviceNames"/> is <see langword="null"/>.</exception>
        public BindingBuilder(
            IBindingConfiguration bindingConfiguration,
            IPlanner planner,
            IConstructorScorer constructorScorer,
            string serviceNames)
        {
            Ensure.ArgumentNotNull(bindingConfiguration, nameof(bindingConfiguration));
            Ensure.ArgumentNotNull(planner, nameof(planner));
            Ensure.ArgumentNotNull(constructorScorer, nameof(constructorScorer));
            Ensure.ArgumentNotNull(serviceNames, nameof(serviceNames));

            this.BindingConfiguration = bindingConfiguration;
            this.Planner           = planner;
            this.ConstructorScorer = constructorScorer;
            this.ServiceNames      = serviceNames;
        }
Ejemplo n.º 31
0
        public void TestSetup()
        {
            sender = Substitute.For <IStreamSender>();
            sender
            .SendAsync(Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>())
            .Returns(SendResult(HerculesStatus.Success));

            planner = Substitute.For <IPlanner>();
            planner
            .WaitForNextSendAsync(Arg.Any <StreamSendResult>(), Arg.Any <CancellationToken>())
            .Returns(Task.CompletedTask);

            log = new SynchronousConsoleLog();

            job = new StreamJob(sender, planner, log, RequestTimeout);
        }
        private void OverrideRestCourse(IPlanner planner, Collection <RestEducationPlanCourse> restCourses)
        {
            foreach (var restCourse in restCourses)
            {
                var course = planner.AllCourses.FirstOrDefault(c => c.Code == restCourse.Code);

                if (course != null)
                {
                    if (restCourse.Priority != 0)
                    {
                        course.Priority = restCourse.Priority;
                    }
                    course.Commentary = restCourse.Commentary;
                }
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Context"/> class.
        /// </summary>
        /// <param name="readonlyKernel">The kernel managing the resolution.</param>
        /// <param name="request">The context's request.</param>
        /// <param name="binding">The context's binding.</param>
        /// <param name="cache">The cache component.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="pipeline">The pipeline component.</param>
        public Context(IReadonlyKernel readonlyKernel, IRequest request, IBinding binding, ICache cache, IPlanner planner, IPipeline pipeline)
        {
            this.Kernel = readonlyKernel;
            this.Request = request;
            this.Binding = binding;
            this.Parameters = request.Parameters.Union(binding.Parameters).ToList();
            this.Cache = cache;
            this.Planner = planner;
            this.Pipeline = pipeline;

            if (binding.Service.GetTypeInfo().IsGenericTypeDefinition)
            {
                HasInferredGenericArguments = true;
                GenericArguments = request.Service.GetTypeInfo().GenericTypeArguments;
            }
        }
Ejemplo n.º 34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:PlanNotFoundException"/> class
 /// </summary>
 /// <param name="planner">The planner, which failed. </param>
 /// <param name="maxPlanLength">Max plan length setting of the planner. </param>
 /// <param name="goal">Goal.</param>
 /// <param name="details">A <see cref="T:System.String"/> that describes the exception. </param>
 /// <param name="inner">The exception that is the cause of the current exception. </param>
 public PlanNotFoundException(IPlanner planner, int maxPlanLength, Goal goal, string details, Exception inner = null)
     : base(
         string.Format(
             MESSAGE_TEMPLATE,
             planner.GetType(),
             maxPlanLength,
             goal.Name,
             details != null ? string.Format(DETAILS_TEMPLATE, details) : ""
             ),
         inner
         )
 {
     this.Planner       = planner;
     this.MaxPlanLength = maxPlanLength;
     this.Goal          = goal;
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Context"/> class.
        /// </summary>
        /// <param name="kernel">The kernel managing the resolution.</param>
        /// <param name="request">The context's request.</param>
        /// <param name="binding">The context's binding.</param>
        /// <param name="cache">The cache component.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="pipeline">The pipeline component.</param>
        public Context(IKernel kernel, IRequest request, IBinding binding, ICache cache, IPlanner planner, IPipeline pipeline)
        {
            Ensure.ArgumentNotNull(kernel, "kernel");
            Ensure.ArgumentNotNull(request, "request");
            Ensure.ArgumentNotNull(binding, "binding");
            Ensure.ArgumentNotNull(cache, "cache");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(pipeline, "pipeline");

            Kernel = kernel;
            Request = request;
            Binding = binding;
            Parameters = request.Parameters.Union(binding.Parameters).ToList();

            Cache = cache;
            Planner = planner;
            Pipeline = pipeline;

            if (binding.Service.IsGenericTypeDefinition)
            {
                HasInferredGenericArguments = true;
                GenericArguments = request.Service.GetGenericArguments();
            }
        }
Ejemplo n.º 36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PerRequestProvider"/> class.
 /// </summary>
 /// <param name="type">The type (or prototype) of instances the provider creates.</param>
 /// <param name="planner">The <see cref="IPlanner"/> component.</param>
 /// <param name="selector">The <see cref="ISelector"/> component</param>
 public PerRequestProvider(Type type, IPlanner planner, ISelector selector)
     : base(type, planner, selector)
 {
 }
 public AddMeetingOption(IMeetingFactory meetingFactory, IPlanner planner, ILogger logger)
 {
     this.meetingFactory = meetingFactory;
       this.planner = planner;
       _logger = logger;
 }
 public AddMeetingOption(Func<DateSpan, string, string[], Meeting> meetingFactory, IPlanner planner)
 {
     this.meetingFactory = meetingFactory;
     this.planner = planner;
 }
Ejemplo n.º 39
0
        //Now that we have some variables/references, we can start by declaring each one of them. So we do it here in the constructor
        public QuickModuleTutorial()
        {
            //Lets start with the receiver
            receiver = new SSLVisionReceiver(IPAddress.Parse("224.5.23.2"), 10002);
            //The constructor to receiver needs the multicast IP and port on which the SSL Vision server is multicasting its packets,
            //These can be found on SSL-Vision settings. Do make sure that your SSL-vision and network is correctly set up.
            //You can test this by first connecting the receiver
            receiver.Connect();
            //Then making a call on receive
            object packet = receiver.Receive();
            if(packet==null)
                throw new Exception("You messed up. Check your network and SSL Vision settings. ");

            //Next, we have the sender
            //Now we provide two kinds of senders, one for GRSim simulator, and another made for XBEE modules, initialize the one you need
            sender = new GRSimSender(IPAddress.Loopback, 10020);
            //Again, the IP address and port are the ones set up on GRSim. Verify them and that your network is good.
            //You can test the sender too, first connect it
            sender.Connect();
            //Now create a RobotParameters object and set some random values i.e.
            RobotParameters roboparams = new RobotParameters();
            roboparams.IsBlue = true;
            roboparams.Id = 1;
            roboparams.XVelocity = 2;
            //And send this packet through the sender
            sender.Send(roboparams);
            //If the robot specified in the robotId above doesn't show any movement, you messed up again.

            //If you need the XBEE sender, then initialize it as
            //sender = new XBeeSender("COM1");
            //where COM1 is the port you connected the XBEE module to
            //Ofcourse the XBEE sender needs the individual velocities to send them, so you need to set the angles between the wheels in each IRobotInfo's
            //WheelAngles property before sending the packet

            //Now comes the controllers, the one we provide is a PIDController, which is a modified implementation of PID by this guy Ron Beyer
            //Firstly, you need to initialize the array of the controllers with length equal to the number of robots you have, or you like to move
            //Lets say you are controlling six robots
            controllers = new PIDController[6];
            //next, initialize each controller with parameters of the robot
            for (int i = 0; i < controllers.Length; i++)
            {
                controllers[i] = new PIDController(i, 2, 0, 0, 3025, -3025, 2, -2, 2, 0, 0, 2025, -2025, 2, -2, 5, 0, 0,
                    2*Math.PI, -2*Math.PI, Math.PI, -Math.PI);
                //Yes its a hell lot of arguments and we did give out a much smaller constructor with default values, but thats the problem, they're default and may not suit
                //your environment. Try to use this constructor. As for what the parameters are, I am not going to spill it out here, I've already given it in the constructor
                //summary, go check there
            }

            //Now comes the module, which is completely your responsibility. Its the module that caused us to get into all this shit. Its the module that caused us to
            //remodel our original program to have only one button named "Deep Shit"
            //Yup you guessed it, the planner.
            //We're not giving out the complete intelligence planner yet even though it contains some basic calculation functions,
            //we do provide a manual controller, which can be used with a Joystick, so connect a joystick
            //but for now, lets stick to some basics behavior, i.e. a test behavior defined in a dummy planner is to follow all the opponent robots
            //Initialize the dummy planner as follows
            planner = new DummyPlanner();

            //Now if you have a working SSL-Vision receiver, you can also safely declare a referee receiver, its not currently being used but you'll need it
            //when you write your own logic for obeying referee commands
            //refereeReceiver = new SSLRefereeReceiver(IPAddress.Parse("224.5.23.3"), 10003);

            //At this point, you have the absolute minimum things you need to run your system.
            //Now you can make individual calls to each of the modules again and agin like

            SSL_WrapperPacket receivedPacket = (SSL_WrapperPacket) receiver.Receive();
            if (receivedPacket != null)
            {
                IRobotInfo[] plannedPoints = planner.PlanExclusive(receivedPacket);
                if (plannedPoints != null)
                {
                    for (int i = 0; i < plannedPoints.Length; i++)
                    {
                        plannedPoints[i] = controllers[i].ComputeExclusive(plannedPoints[i],
                            receivedPacket.detection.robots_blue[plannedPoints[i].Id]);
                    }
                    foreach(var pointWithVelocity in plannedPoints)
                        sender.Send(pointWithVelocity);
                }
            }
            //and putting it in an infinite loop, which is pretty hideous if you ask me
            // or you can automate the process with the rest of useful architecture we provided, for example;

            //The data repository is a kind of utility we created to parse the incomming commands and store incomming/outgoing data in an organized way,
            //its a good software practice so if you want to use it, you can initialize it too
            dataRepository = new DataRepository(3, true);
            //The repository also stores previous packets, which is useful for interpolation techniques. The size of history is given as the constructor argument
            //The repository can be plugged in each of the above modules as follows. The modules will automatically read/write on repository

            IDataSource sourceReference = (IDataSource) receiver;
            sourceReference.Repository = dataRepository;
            sourceReference = (IDataSource) sender;
            sourceReference.Repository = dataRepository;
            foreach (var controller in controllers)
            {
                sourceReference = (IDataSource) controller;
                sourceReference.Repository = dataRepository;
            }
            sourceReference = (IDataSource) planner;
            sourceReference.Repository = dataRepository;
            //To keep track of your game configuration, configure the data source too, i.e. add the id's of the robots that you are using. you can access it in your planner
            for (int i = 0; i < 6; i++)
                dataRepository.Configuration.AddRobot(i, null);
            //Its also advised to use the OnRefereeCommandChanged method to notify the planner whenever a change in referee command status occurs
            //This is done by assigning the method as follows
            dataRepository.OnRefereeCommandChanged += planner.OnRefereeCommandChanged;

            //And we provide execution engines, which, as the name says execute your tasks. All you have to do is define a sequence of tasks
            //First select an anchor task which acts as starting point and branches onto all other tasks.
            //Now each of the above modules also implements and ITask interface which is essentially what each ExecutionEngine uses
            //So, evidently, the sequence begins with reception of packet. So here's the anchor
            ITask anchor = (ITask) receiver;

            //To build the sequence of what comes next, we assign a delegate to the GetNext property of the anchor. The delegate returns an array of tasks,
            //These tasks are the ones the engine will perform after the anchor's task has been performed.
            //The next task should be to plan, so
            anchor.GetNext = () => new[] {(ITask) planner};

            //I've used the fancy lambda expression. It may look berserk but once you get to understand them they're quite handy
            //Alternately, you can create a method with a signature matching the GetNextTasks, and in its body, return an array of ITask, i.e. the tasks you want performed next
            //This is how:
            //
            //public ITask[] plannerReturner()
            //{
            //    ITask[] array = new ITask[1];
            //    array[0] = (ITask) planner;
            //    return array;
            //}
            //
            //And assign it
            //anchor.GetNext = new GetNextTasks(plannerReturner);

            //Next we take the planner and assign it a next sequence of tasks, which would be the controllers
            ITask anotherReference = (ITask) planner;
            anotherReference.GetNext = () =>
            {
                ITask[] controllerTasks = new ITask[controllers.Length];
                for (int i = 0; i < controllers.Length; i++)
                    controllerTasks[i] = (ITask) controllers[i];
                return controllerTasks;
            };

            //Next the controllers need to queue the tasks to send the data
            foreach (var controller in controllers)
            {
                anotherReference = (ITask) controller;
                anotherReference.GetNext = () => new[] {(ITask) sender};
            }

            //and the sender is the terminal
            //Now lets bring in the execution engine, i'm going to go with the single processor, parallel processor's kinda experimental. Feel free to play with it if you want
            executionEngine = new SingleProcessor(new[] {anchor});
            //The processor takes an array of starting points/anchors.
            //Now all you have to di is start the engine
            executionEngine.Start();

            //And voila, you're done. Each module's ITask interface exposes the Execute() method which is called by the processor.
            //Remember how we plugged in a repository to each module, each module's Execute() takes care of taking data and writing it.
            //Ofcourse, to keep this model working, I would advise you to follow the design pattern here. i.e. If you create a module
            //by yourself according to your needs, it needs to implement one of the module specific interfaces e.g. IPacketSender for
            //anything that sends outgoing packets, IPlanner for strategy planning/path planning modules, IController for any other
            //position to velocity generation controller. The module must also implement two additional interfaces i.e. ITask and IDataSource
            //after which the module can easily be plugged in this model.

            //This project is a work in progress, and also contains a Rig module that has all of the above done in it, and a GUI that
            //can completely configure and manage multiple Rigs. We hope to complete it soon. This tutorial is an absolute basic,
            //you can navigate to different classes for better understanding. Feel free to ask us if you don't understand anything about
            //this project, YES ONLY THIS PROJECT, don't bother us if you don't know how to work around events, or if you don't understand
            //the concept of Threads, References or environment specific stuff. Try searching for these before.

            //Finally, we're all humans and we all make mistakes. This thing is not error proof, heck its not even tested properly.
            //So if you do find any bugs do feel free to report them to us so we can reflect it here. Remember, the basic purpose is
            //to learn, so don't be selfish. We're kind enough to give our work out to you, be kind yourselves.
            //Also take into consideration to contribute to this project and become an active member of something that might help a lot
            //of generations to come.
        }
 public ListEventsOption(IPlanner planner)
 {
     this.planner = planner;
 }
 public AddTodoOption(Func<DateSpan, string, Todo> todoEventFactory, IPlanner planner)
 {
     this.todoEventFactory = todoEventFactory;
     this.planner = planner;
 }
 public AddTodoOption(ITodoFactory todoEventFactory, IPlanner planner, ILogger logger)
 {
     this.todoEventFactory = todoEventFactory;
       this.planner = planner;
       _logger = logger;
 }