# -*- python -*-

load(
    "@drake//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)
load("//tools/lint:lint.bzl", "add_lint_tests")

package(default_visibility = ["//visibility:public"])

drake_cc_package_library(
    name = "trajectory_optimization",
    deps = [
        ":direct_collocation",
        ":direct_transcription",
        ":generalized_constraint_force_evaluator",
        ":joint_limit_constraint_force_evaluator",
        ":multiple_shooting",
        ":position_constraint_force_evaluator",
    ],
)

drake_cc_library(
    name = "generalized_constraint_force_evaluator",
    srcs = ["generalized_constraint_force_evaluator.cc"],
    hdrs = ["generalized_constraint_force_evaluator.h"],
    deps = [
        "//common:essential",
        "//math:autodiff",
        "//multibody:rigid_body_tree",
        "//solvers:evaluator_base",
    ],
)

drake_cc_library(
    name = "position_constraint_force_evaluator",
    srcs = ["position_constraint_force_evaluator.cc"],
    hdrs = ["position_constraint_force_evaluator.h"],
    deps = [
        ":generalized_constraint_force_evaluator",
        "//math:autodiff",
        "//multibody:kinematics_cache_helper",
    ],
)

drake_cc_library(
    name = "joint_limit_constraint_force_evaluator",
    srcs = ["joint_limit_constraint_force_evaluator.cc"],
    hdrs = ["joint_limit_constraint_force_evaluator.h"],
    deps = [
        ":generalized_constraint_force_evaluator",
        "//math:autodiff",
    ],
)

drake_cc_library(
    name = "multiple_shooting",
    srcs = ["multiple_shooting.cc"],
    hdrs = ["multiple_shooting.h"],
    deps = [
        "//common:essential",
        "//common/trajectories:piecewise_polynomial",
        "//solvers:mathematical_program",
        "//systems/framework",
    ],
)

drake_cc_library(
    name = "direct_collocation",
    srcs = [
        "direct_collocation.cc",
    ],
    hdrs = [
        "direct_collocation.h",
    ],
    deps = [
        ":multiple_shooting",
        "//math:autodiff",
        "//math:gradient",
    ],
)

drake_cc_library(
    name = "direct_transcription",
    srcs = [
        "direct_transcription.cc",
    ],
    hdrs = [
        "direct_transcription.h",
    ],
    deps = [
        ":multiple_shooting",
        "//math:autodiff",
        "//math:gradient",
        "//systems/primitives:linear_system",
        "//systems/primitives:piecewise_polynomial_linear_system",
    ],
)

# === test/ ===

drake_cc_googletest(
    name = "multiple_shooting_test",
    deps = [
        ":multiple_shooting",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "direct_collocation_test",
    deps = [
        ":direct_collocation",
        "//common/test_utilities:eigen_matrix_compare",
        "//systems/primitives:linear_system",
    ],
)

drake_cc_googletest(
    name = "direct_transcription_test",
    deps = [
        ":direct_transcription",
        "//common/test_utilities:eigen_matrix_compare",
        "//systems/primitives:piecewise_polynomial_linear_system",
    ],
)

drake_cc_library(
    name = "generalized_constraint_force_evaluator_test_util",
    testonly = 1,
    srcs = [
        "test/generalized_constraint_force_evaluator_test_util.cc",
    ],
    hdrs = ["test/generalized_constraint_force_evaluator_test_util.h"],
    data = [
        "//examples/simple_four_bar:models",
    ],
    deps = [
        "//attic/multibody/parsers",
        "//common:find_resource",
    ],
)

drake_cc_googletest(
    name = "position_constraint_force_evaluator_test",
    deps = [
        ":generalized_constraint_force_evaluator_test_util",
        ":position_constraint_force_evaluator",
        "//common/test_utilities:eigen_matrix_compare",
        "//math:autodiff",
    ],
)

drake_cc_googletest(
    name = "joint_limit_constraint_force_evaluator_test",
    deps = [
        ":generalized_constraint_force_evaluator_test_util",
        ":joint_limit_constraint_force_evaluator",
        "//common/test_utilities:eigen_matrix_compare",
        "//math:autodiff",
    ],
)

add_lint_tests()
