Program Listing for File TaskPlanner.hpp

Return to documentation for file (/tmp/ws/src/rmf_task/rmf_task/include/rmf_task/TaskPlanner.hpp)

/*
 * Copyright (C) 2020 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/

#ifndef RMF_TASK__AGV__TASKPLANNER_HPP
#define RMF_TASK__AGV__TASKPLANNER_HPP

#include <rmf_task/Request.hpp>
#include <rmf_task/RequestFactory.hpp>
#include <rmf_task/CostCalculator.hpp>
#include <rmf_task/Constraints.hpp>
#include <rmf_task/Parameters.hpp>
#include <rmf_task/State.hpp>

#include <rmf_utils/impl_ptr.hpp>

#include <vector>
#include <memory>
#include <functional>
#include <variant>

namespace rmf_task {

//==============================================================================
class TaskPlanner
{
public:

  class Configuration
  {
  public:
    Configuration(
      Parameters parameters,
      Constraints constraints,
      ConstCostCalculatorPtr cost_calculator);

    const Parameters& parameters() const;

    Configuration& parameters(Parameters parameters);

    const Constraints& constraints() const;

    Configuration& constraints(Constraints constraints);

    const ConstCostCalculatorPtr& cost_calculator() const;

    Configuration& cost_calculator(ConstCostCalculatorPtr cost_calculator);

    class Implementation;

  private:
    rmf_utils::impl_ptr<Implementation> _pimpl;
  };

  class Options
  {
  public:

    Options(
      bool greedy,
      std::function<bool()> interrupter = nullptr,
      ConstRequestFactoryPtr finishing_request = nullptr);

    Options& greedy(bool value);

    bool greedy() const;

    Options& interrupter(std::function<bool()> interrupter);

    const std::function<bool()>& interrupter() const;

    Options& finishing_request(ConstRequestFactoryPtr finishing_request);

    ConstRequestFactoryPtr finishing_request() const;

    class Implementation;
  private:
    rmf_utils::impl_ptr<Implementation> _pimpl;
  };

  class Assignment
  {
  public:

    Assignment(
      rmf_task::ConstRequestPtr request,
      State finish_state,
      rmf_traffic::Time deployment_time);

    // Get the request of this task
    const rmf_task::ConstRequestPtr& request() const;

    // Get a const reference to the predicted state at the end of the assignment
    const State& finish_state() const;

    // Get the time when the robot begins executing
    // this assignment
    const rmf_traffic::Time deployment_time() const;

    class Implementation;

  private:
    rmf_utils::impl_ptr<Implementation> _pimpl;
  };

  enum class TaskPlannerError
  {
    low_battery,

    limited_capacity
  };

  using Assignments = std::vector<std::vector<Assignment>>;
  using Result = std::variant<Assignments, TaskPlannerError>;

  TaskPlanner(
    Configuration configuration,
    Options default_options);

  TaskPlanner(
    const std::string& planner_id,
    Configuration configuration,
    Options default_options);

  const Configuration& configuration() const;

  const Options& default_options() const;

  Options& default_options();

  Result plan(
    rmf_traffic::Time time_now,
    std::vector<State> agents,
    std::vector<ConstRequestPtr> requests);

  Result plan(
    rmf_traffic::Time time_now,
    std::vector<State> agents,
    std::vector<ConstRequestPtr> requests,
    Options options);

  double compute_cost(const Assignments& assignments) const;

  class Implementation;

private:
  rmf_utils::impl_ptr<Implementation> _pimpl;

};

} // namespace rmf_task

#endif // RMF_TASK__AGV__TASKPLANNER_HPP