Giter Club home page Giter Club logo

flatland-asp's Introduction

Flatland ASP

Flatland ASP deals with the application of Answer Set Programming techniques to the Flatland environment.

Its first goal is to provide a short introduction to Flatland as well as to Answer Set Programming, more precisely Clingo, with the help of documentation and examples.

The second and more exciting goal is to explore various ASP instantiations and encodings of the Flatland environment in order to find solutions to the problems Flatland tries to help to solve.

For any information that goes beyond this README, please visit the FlatlandASP Wiki or refer to the Link section

Table of Contents
  1. Getting Started
    1. Prerequisites
    2. Installation
  2. General Project Structure
  3. Links

Getting started

To get this project up and running, just follow these simple steps.

Prerequisites

In order to get FlatlandASP up and running the only prerequisite is Python. To avoid conflicts with Flatland it is currently recommended to use Python 3.10.

Installation

  1. Clone this repository
git clone https://github.com/VictosVertex/flatland-asp.git
  1. Create a new python virtual environment (or use an existing one)
py -m venv my_new_python_environment
  1. Activate the virtual environment

    Windows

    cmd.exe

    source my_new_python_environment/Scripts/activate.bat

    PowerShell

    source my_new_python_environment/Scripts/activate.ps1
    Linux

    (depending on distribution):

    bash

    source my_new_python_environment/bin/activate
  2. Go into cloned repository directory

  3. Install the project as an editable package

pip install -e .

The project is now ready to be used in any project using the python virtual environment.

back to top

General Project Structure

  • data/
    • data/encodings/ ASP encodings
    • data/environments/ Environment data (.json) and environments (.pkl)
  • examples/ Examples for Flatland and ASP (Clingo)
  • src/flatlandasp
    • src/flatlandasp/core/flatland Flatland related classes, schemas, mappings, static maps, etc.
    • src/flatlandasp/core/asp ASP/Clingo related instance descriptions, generators, etc.
    • src/flatlandasp/core/utils Utility functions for files, images, etc.
    • src/flatlandasp/features/ Modular features building on core/each other, API endpoints

Links

Useful links for more information on Flatland and Clingo

back to top

flatland-asp's People

Contributors

victosvertex avatar

Stargazers

 avatar

Watchers

 avatar

flatland-asp's Issues

Separate FlatlandASP

Because of the shift towards an API, the FlatlandASP class can be split into a solver and a simulator.

Each of these end up as separate features:

  • solver with statistics, models and actual solutions
  • simulator to simulate/test and visualize the solution in the environment at each step

Introduce new (base?) instance generation.

The asp instance generation should be completely independent of the encoding. Thus a minimum instance description should be provided that only describes the flatland environment in terms that are a direct representation.

Suggestion:

  • cells with coordinates, orientation and possible directions
  • schedule with agent id, start and target positions, starting orientation and earliest departure
  • some map that maps a direction to an actual position change

API: Endpoint to save maps

In order to save custom maps, for example created in an editor, an endpoint to save them is necessary.

This endpoint should accept very specific input.

Environment storage and retrieval

It should be possible to store either an entire Flatland environment or at least enough information to recreate a given environment.

EDIT: Some additional features are required:

Add a functionality to uniquely identify solutions.

The user should be able to view models, paths, actions, statistics etc. of any already found solution.
To achieve this, the solution has to be uniquely identifiable.

One way could be, to simply add environment_name, encoding_name and number_of_agents into the file name of the solution. This approach would however result in potentially very large urls if the name is used as a query parameter.

Another approach could be to instead take these parameters, hash them to some fixed length and use this hash as a unique identifier.

A file could be added which stores hashes and their respective configurations.

Add max_episode_steps in simulator

The calculated horizon Flatland provides can be too small under certain circumstances as it ignores collisions which may force trains to take way longer paths than the shortest ones.

Thus a way should be added to set the limit manually in case it doesn't fit (or find a better formula)

Remove .reset() call from the FlatlandASP solver and simulator.

Calling .reset() on Flatland environments inside of the solver and simulator introduces a side effect that's hidden for outside viewers.

Instead the call to reset should be done after instantiating the environment and the already reset environment should be provided to both, solver and simulator.

Recently an error occurred in a similar project (actually the error occured twice in different ones) because the developers did not call .reset(). They then tried to find help in my project, but since the call to .reset() was hidden, they - and I myself after investigating their problem - spent too much time realizing that all that was missing was a simple .reset() call. If that call was outside the classes instead of in their initialization methods the solution would've been immediately obvious.

Remove unused files

Some files got pushed that are no longer in use or shouldn't have been pushed in the first place. They should be removed to clean up the project.

Clean up main.py

main.py should be the entrypoint of this application, it should only be concerned with setting up the necessary basis like api with routers and actually run the server.

Improve testability of FlatlandASPSolver.

Currently the solver seems to have too many (and apparently confusing) side effects.

  • creates an instance, currently the name can't be set, only the instance generator
  • uses fixed step_limit
  • adds .lp to encoding name which actually already caused confusion when someone used the project
  • save takes the solver data and stores it in a json file

The problem:

The class so far seems like a mix between an abstraction over clingo/flatland and not being one. I think the class should be either changed to be a real abstraction (probably no clingo control as input, fixed subset of allowed parameters) or to not be one at all.

Suggestions for removing abstraction:

  • remove instance creation entirely from the solver, instead of an instance generator it should directly take in an instance (this also removes the step_limit side effect)
  • remove save function, storing json should instead be a normal file utility
  • don't add .lp inside the solver

Further thoughts:

If all suggestions are implemented, the solver would just use normal clingo functionality such as adding the encoding to the clingo control, ground and solve. The only actually useful functionality left would be the extraction of the last model/solution data. So instead of a solver this just is a callback container.

BaseInstance should be renamed/removed

Because of the future introduction of an actual base instance that is independent of encodings, thus only provides the actual minimum data, the old BaseInstance is no longer the base.

It should be considered to completely rework the instance generation because if the instance is independent and only a single one is used, then the entire concept of multiple instance formats is not of any use.

Add section to readme that explains how to use app.

Since the project changed from being a package (because it was too small and meaningless) to an application (in the form of a backend API) the user now should be presented with information on how to run and interact with it.

sparse_line_generator can't resolve orientation

In the last added environments the sparse_line_generator can't find a proper orientation because all city orientations are set to 0.

To solve this the proper city orientation should be supplied. This requires a corresponding issue in FlatlandASPView.

All maps should be replaced with versions using proper orientations.

Move either instance generation (to feature) or environment storage/generation (to core).

Currently ASP instance generation/storage is part of the core capability of FlatlandASP. This makes sense, as it works with basic structures and generating instances from an environment is a fudnamental functionality required for the project to even be functional.

However the same could be said about environment generation/storage, which currently resides in the environments feature.

This seems inconsistent and should be changed. Either both are part of separate features (ASP instance generation could be part of the solver) or both are part of core.

Add custom logger config

A custom logger config would be beneficial as it can show which module has logged which messages, granted logging modules create a new logger with a name.

Add a way to get an environment directly from json

environment_crud so far only provides the ability to load directly from pickle or load EnvironmentData, it should be possible to load environmetns from json just like from pkl. Maybe add an optional parameter for agent variability and a custom line generator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.