Esempio n. 1
0
def create_multiagent_env():
    """
    :return:
    e: multi-agent UUVEnv
    consmdp: Underlying consumption MDP of the environment
    targets: set of targets
    num_agents: number of agents
    init_state: set of initial states
    """
    #env_multiagent setup function
    setup()
    #generate environment
    init_state = [545, 95, 157]
    targets = [454, 64, 547, 372, 183, 155, 611]

    #targets = [454, 10, 547, 872, 183, 135, 411]
    init_state = [452, 664, 123]
    targets = [125, 164, 247, 572, 383, 355, 411]
    #targets = [312, 164, 247, 572, 383, 355, 411]

    init_state = [32, 74, 398]
    targets = [23, 44, 93, 112, 87, 93, 35]
    num_agents = 5

    init_state = list(random.sample(range(gridsize * gridsize), num_agents))
    targets = list(random.sample(range(gridsize * gridsize), 60))
    print(init_state)
    #, 136]
    #, 203, 272]
    reload_list = [22, 107]
    reload_list = []
    for item in targets:
        reload_list.append(item)
    # for item in init_state:
    #     reload_list.append(item)
    e = SynchronousMultiAgentEnv(
        num_agents=num_agents,
        grid_size=[gridsize, gridsize],
        capacities=[100 for _ in range(num_agents)],
        reloads=reload_list,
        targets=targets,
        init_states=init_state,
        enhanced_actionspace=0)  #generate consumption MDP
    #generate consumption mdp
    e.create_consmdp()
    consmdp1 = e.get_consmdp()
    consmdp = consmdp1[0]
    #generate targets
    targets = e.targets
    #print(targets)
    return e, consmdp, targets, num_agents, init_state
# # Test computation of minimal capacity
import fimdp
from fimdpenv import setup
setup()
from uuvmodel import create_env
from uuvmodel import animate_simulation, calc_exptimetotarget, visualize_multisnapshots
from fimdp.energy_solvers import GoalLeaningES, BasicES
from fimdp.objectives import AS_REACH, BUCHI, MIN_INIT_CONS, POS_REACH, SAFE
#from reachability_examples import ultimate
#from fimdp.energy_solver import AS_REACH
#from fimdp.energy_solver import BUCHI
from fimdp.mincap_solvers import bin_search
import matplotlib.pyplot as plt
from networkx.algorithms import tournament
from fimdp.core import CounterStrategy

#import MarsEnv
import numpy as np
import scipy.optimize
from scipy.optimize import linear_sum_assignment
import networkx as nx
import math
import multi_agent_codes
from fimdpenv import setup, UUVEnv
from fimdpenv.UUVEnv import SynchronousMultiAgentEnv
import random

#from fimdpenv.env_multiagent import setup
#from env_multiagent import visualize_allocation

#from env_multiagent import create_env
Esempio n. 3
0
# # Strategy types
# The FiMDP package offers several solvers that can generate strategies for the considered objectives. In this notebook, we focus on the Büchi objective and discuss solvers that all:
#  * solve almost-sure Büchi objective and
#  * compute the minimal initial load needed in each state.
# In other words, all the solvers have the same guarantees. Where they differ are the strategies they produce. Our overall goal is to provide strategies that not only provide these guarantees but are also **usable in practical control case studies**.
#
# We use a simple gridworld underwater environment generated by [FiMDPEnv] to demonstrate the behavior we can obtain using different solvers of the [FiMDP] package. We have some pre-defined environments in the file [env.py](env.py). The goal of the agent is to reach the green target with sufficient energy so that it can reach it again and again.
#
# In each cell of the gridworld, the agent can choose one of eight possible actions. For each of the 4 directions (`NORTH`, `SOUTH`, `WEST`, `EAST`) the agent chooses whether to play a *weak* or _strong_ action. A strong action costs more energy, while the weak action has uncertain outcome. The resulting direction of movement can be affected by pre-defined currents. For example, in most cases, picking `EAST` can, with a small probability end up with the agent going `SOUTH` or `NORTH`.
#
# [FiMDP]: https://github.com/xblahoud/FiMDP
# [FiMDPEnv]: https://github.com/pthangeda/FiMDPEnv

import fimdpenv

fimdpenv.setup()
from env import create_env

e = create_env('2R-1T-simple', heading_sd=0.32, agent_capacity=40)
e

# The colors of the gridworld cells have the following semantics:
#  * <font color='blue'>Blue Cell</font>: Current location of the agent
#  * <font color='gray'>Gray Cells</font>: Trajectory of the agent
#  * <font color='green'>Green Cells</font>: Target States
#  * <font color='orange'>Orange Cells</font>: Reload states

# This package offers 2 solvers that generate strategies:
#  * Basic solver (class `BasicES`)
#  * Goal-leaning solver (class `GoalLeaningES`)