Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to add an object at runtime? #286

Closed
1 of 7 tasks
centeio opened this issue May 13, 2021 · 4 comments
Closed
1 of 7 tasks

Is it possible to add an object at runtime? #286

centeio opened this issue May 13, 2021 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@centeio
Copy link

centeio commented May 13, 2021

What is your question?
Is it possible to add an object to the world at runtime?

I would like to change the blocks in the drop-off zones in runtime. Is this possible? What's the best way to do this? I see you have the action RemoveObject, but not the AddObject. In any case, I'd like to add it to a specific position (no need of getting an agent involved and all its characteristics).
I have also considered altering the state of the world through the perception of one "ghost" agent. Does that work?

Thanks!

To what is your question related?

  • I am not sure if I should use MATRX.
  • I have a question about the idea behind MATRX.
  • I don't know how to do something with MATRX.
  • I don't know where to find something.
  • I think I found a bug, but I am not sure.
  • I want to contribute, but don't know where to start.
  • Something else.
@centeio centeio added the question Further information is requested label May 13, 2021
@jwaa
Copy link
Member

jwaa commented May 13, 2021

This should be possible yes! As long as the object is not an agent. I will look into it tomorrow to see if I can make a code snippet for you. Otherwise I will implement a add_object for you.

You do need some access point to the world though. So through another object or agent (with agent making more sense). Which ofcourse can be an invisible one just doing its thing of adding that object.

Through altering the State won't work. As the State in a agent is simply its perceptions, not the actual world.

@thaije
Copy link
Collaborator

thaije commented May 13, 2021

It's actually also possible to add a new agent on the fly, as can be seen in this Covid Triage tool MATRX case here: https://github.com/matrx-software/MHC-for-triage-agents/blob/00ca653b798cd8a0302a33870fa54d483c13e2ba/mhc/patient_planner.py#L293.

However, I think it's best if we add an add_object action as you suggest @jwaa and maybe also an add_agent object that takes care of all the checks such as valid object placement etc for you.

@centeio
Copy link
Author

centeio commented May 14, 2021

Thank you both! I think I managed, by using a similar process as @thaije mentioned.

Created class AddGhostBlock(Action).

     class AddGhostBlock(Action):

        def __init__(self, duration_in_ticks=0):
            super().__init__(duration_in_ticks)

        def is_possible(self, grid_world, agent_id, **kwargs):

            # check that we have all variables
            # TODO

            # success
            return AddObjectResult(AddObjectResult.ACTION_SUCCEEDED, True)


        def mutate(self, grid_world, agent_id, **kwargs):

            obj_body_args = {
                "location": [24,10],
                "name": "Collect Block",
                #"class_callable": GhostBlock,
                "visualize_colour": '#332288',
                "visualize_shape": 0,
                "drop_zone_nr": 1
            }

            # create the new object
            env_object = GhostBlock(**obj_body_args)

            # register the new object
            grid_world._register_env_object(env_object)

            return AddObjectResult(AddObjectResult.ACTION_SUCCEEDED, True)

@jwaa
Copy link
Member

jwaa commented May 14, 2021

@centeio Thanks for contributing your code block! I will use it as the basis of the AddObject action and integrate in the upcoming version. See #287

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants