How can I create a rail network, which is just a simple circle?

Hey Guys,
I am trying to understand the basics of the flatland environment. I guess this will be the stupidest question on this forum, but I am feeling lost … I have to ask.

How can I create a rail network, which is just a simple circle ?

My Idea was to follow the “Simple Example 1 : Basic Usage”. But how would the specs look like ? There is no Tile for corners and the environment does not create them itself …

I would be glade, if there is anyone willing to answer such a simple question.


Hello @fhohnstein,

This is not a stupid question at all, actually creating such an environment wouldn’t be so easy!

So, one solution would be as you mentioned to use the rail_from_manual_specifications_generator generator, and to “draw” the environment yourself. But that would be complicated! Building such maps ny hand is not easy.

@hagrid67 had developed an editor system, I don’t know if it still works with recent Flatland releases?

In any case, you probably don’t need to create the environments by yourself. An easier way to create simple environments is to use the sparse railway generator and to play with its parameters.

If you want to run simple experiments, you can set the number of agents to 1, make the environment 25x25 and a low number of cities.

Check out this Colab notebook for a concrete example:

Download Execute In Colab

Also, I am curious, you mention the old documentation ( How did you end up on that page?

We have moved everything to the new doc, which contains the same information but more up to date (eg for that page: Is there an outdated link to the old doc somewhere?

1 Like

Hi @fhohnstein - there are a couple of notebooks in the flatland repo which might be of interest.

Scene-editor.ipynb should allow you to draw some rails by dragging the mouse. There are some buttons to load & save etc. It’s a bit broken when it comes to adding agents and targets though.

test-collision.ipynb creates a simple environment on-the-fly using which is related to the editor. It applies simulated mouse-strokes, specified by (row,column) co-ordinates, similar to how the editor works. The one used in the test case is called “concentric_loops” and is defined in ddEnvSpecs like this:

        # Concentric Loops
        "concentric_loops": {
            "llrcPaths": [
                [(1,1), (1,5), (8, 5), (8,1), (1,1), (1,3)],
                [(1,3), (1,10), (8,10), (8,3)]
            "lrcStarts": [(1,3)],
            "lrcTargs": [(2,1)],
            "liDirs":  [1]

When defining the “strokes” (llrcPaths means list of list of row,col paths to me :slight_smile:) you need to make the ends of the strokes overlap a bit, and then it can work out how to join the rails. (This applies if you’re doing it by hand in the editor too.)

Hope that helps!



I am trying to do 2 things:

  • Create a rail-network of a specific shape- not random networks that available functions seem to create.
  • Schedule multiple trains between the same pair of source (initial position) and destination (target) after regular intervals.

After exploring flatland documentation for few days, thanks to MasterScrat, I found this could be done using Scene_Editor.ipynb (see notebooks in flatland env.). However, it is a painfully slow process to even create a simple network. Moreover, I am unable to create multiple agents as pressing Ctrl+k does not create a new agent but only moves the old agent around.

Is there a more convenient way to generate customised rail networks- may be based on node and link information of underlying network structure? Moreover, how can I generate customised schedules of multiple agents (start time in addition to initial and target locations)?

For the environment edition process, @hagrid67 would know better. I don’t think there will be better than the Scene_Editor.ipynb notebook.

If you do create useful editing tools or test environments, they would be nice submissions to the Community Prize BTW :wink:

Regarding schedules, there’s no pre-defined “start time” as part of the environments. The agents can start moving whenever they want, assuming the way is clear. This is something that should be handled at the policy level, and not at the environment level. Or did I misunderstand your question?

Hi,hagrid67!I’m doing a research that based on Flatland,and i need to build a railway net seems like the railway in real life.I saw your reply about using Scene-editor can build the railway by my self,but i couldn’t find the nbextention named jpy_canvas.Could you tell me how can i install all the depended extention and could you tell me some method of build a railway net by myself?Whether the work is feasible or it’s really a hard work? My email is ,we can also communicate by email. Hope for ypur reply,thank you!

Hi very sorry for the 6 week delay(!), someone at AICrowd very kindly just brought your note to my attention.

Yes it appears the author of the jpy_canvas extension removed it from his public github some months ago; I think it had stopped working with the latest jupyter some time earlier. I think it’s just about possible to get things working by pinning to old versions but that’s not the way any of us want to go.

At some point I expect we will refresh the editor to work with the newer, more maintained canvas extension ipycanvas (github) but there are no immediate plans for this.

We’ve done a couple of bits of related work in the last 6-9 months:

  • one of which involved converting some real layout data into flatland environments.
  • using manually coded coordinate strokes (like mouse-strokes in the editor) to create specific environments.

These both used some of the old editor code to handle some of the logic of joining rails etc. (The older hand-coded test environments literally had to have explicit decimal / binary numbers representing the transitions)

I’ll try to put some information together, maybe in a branch. Please ping us again here or in an issue if you’re still interested in this.

Many thanks!

1 Like