Skip to content
Snippets Groups Projects
task.py 1.69 KiB
Newer Older
import time
import uuid
Guilhem Saurel's avatar
Guilhem Saurel committed

Guilhem Saurel's avatar
Guilhem Saurel committed
import numpy as np
Guilhem Saurel's avatar
Guilhem Saurel committed

Guilhem Saurel's avatar
Guilhem Saurel committed
    rcost_x = 0.1
    rcost_u = 0.2
    tcost_x = 3.0
Guilhem Saurel's avatar
Guilhem Saurel committed

    model = crocoddyl.ActionModelUnicycle()
Guilhem Saurel's avatar
Guilhem Saurel committed
    model.costWeights = np.array([rcost_x, rcost_u])
    modelT = crocoddyl.ActionModelUnicycle()
    modelT.costWeights = np.array([tcost_x, 0])
    state = np.zeros(3)
    problem = crocoddyl.ShootingProblem(state, [model] * horizon, modelT)
Guilhem Saurel's avatar
Guilhem Saurel committed
    return crocoddyl.SolverDDP(problem)

Guilhem Saurel's avatar
Guilhem Saurel committed
    """Common information to all tasks, to be allocated by each minion and the boss."""

Guilhem Saurel's avatar
Guilhem Saurel committed

Guilhem Saurel's avatar
Guilhem Saurel committed
    def __init__(self, ddp, converged=True):
        self.converged = converged
Guilhem Saurel's avatar
Guilhem Saurel committed
        self.x0 = ddp.problem.x0.copy()
        self.xs = np.array(ddp.xs)
        self.us = np.array(ddp.xs)
        self.v = ddp.cost
        self.Vx = ddp.Vx[0].copy()
        self.Vxx = ddp.Vxx[0].copy()
        self.iter = ddp.iter
Guilhem Saurel's avatar
Guilhem Saurel committed
    def __init__(self, x0s, identifier=None):
Guilhem Saurel's avatar
Guilhem Saurel committed
        """
Guilhem Saurel's avatar
Guilhem Saurel committed
        Set a task with a list of initial state.
        Identifier is a uniq identifier of the task (for documentation only)
        that is generated randomly if none is provided.
Guilhem Saurel's avatar
Guilhem Saurel committed
        """
Guilhem Saurel's avatar
Guilhem Saurel committed
        self.identifier = identifier if identifier is not None else uuid.uuid1()
        self.time = 0
        self.x0s = x0s
        self.results = []

    def work(self):
        start = time.perf_counter()

        ddp = TaskParameters.ddp
        for x0 in self.x0s:
            ddp.problem.x0 = x0.copy()
            res = ddp.solve()
Guilhem Saurel's avatar
Guilhem Saurel committed
            self.results.append(Result(ddp, res))

        self.time = time.perf_counter() - start


if __name__ == "__main__":
Guilhem Saurel's avatar
Guilhem Saurel committed
    task = Task(np.random.rand(10, 3))