jakobaxelsson / sossim

A system-of-systems (SoS) simulator
MIT License
0 stars 0 forks source link

Make model.GridNetworkSpace a subclass of mesa.space.NetworkGrid #2

Closed jakobaxelsson closed 1 year ago

jakobaxelsson commented 1 year ago

The Mesa space package contains different types of spaces. None of these is totally appropriate, and therefore a custom GridNetworkSpace is provided in the model module. However, it does not implement the same API as the standard Mesa space types, and should be better aligned with those.

A complicating factor is that there is no common base class for Mesa spaces, and hence it is a bit unclear exactly what the API should look like. Some reverse engineering is needed into Mesa spaces to see what methods recurr in the different kinds of spaces.

jakobaxelsson commented 1 year ago

Some methods to include and to be used by other classes:

However, there is already a class mesa.space.NetworkGrid that contains these methods. This should be the base class of the road network class! Issue is renamed to reflect this! The GridNetworkSpace class should also change its name to RoadNetworkGrid.

jakobaxelsson commented 1 year ago

A problem with making the RoadNetworkGrid a subclass of mesa.space.NetworkGrid is that the latter assumes that network id's are int, whereas the former assumes them to be tuples (x, y). Probably, it makes more sense to have them as ints, and add x, y as attributes to the node.

jakobaxelsson commented 1 year ago

An alternative is to have ids as integers in range(0, size_x size_y 16). Then, the node with network position (x, y) has id = y size_x 4 + x. Or, inversely, y = id // (size_x 4), x = id % (size_x 4).

Nodes in the detailed road network are only added when adding edges using the method add_edges of the RoadNetworkGrid. So it is probably only there that changes are needed to make the node ids integers, and adding x, y attributes to the nodes.

jakobaxelsson commented 1 year ago

Major revision done of space representation. It is now a grid network with edges between all adjacent grid nodes. Roads and destinations are represented by attributes, which leaves room for easily adding more node and edge attributes for more detailed landscapes.

jakobaxelsson commented 1 year ago

The API of Mesa's GridNetwork space has been implemented and is used. However, it would be good to remove all references to the road network from other modules, and instead extend the API of the space itself to include all needed methods.

jakobaxelsson commented 1 year ago

All external references to road_network have been removed. Other modules now work exclusively with the methods provided by the space itself.