gtri / scrimmage

Multi-Agent Robotics Simulator
https://www.scrimmagesim.org
Other
156 stars 94 forks source link

Enable concatenation of mission files #581

Closed dmagree closed 1 month ago

dmagree commented 10 months ago

It would be useful to be able to chain mission files together. For example, a user may want to separate different configurations of entities into standalone files, that then can be referenced from a primary mission file.

I envision it working with a mission_file_child xml tag, that would trigger a file lookup when found in MissionParse::parse. The child file would then be parsed and its nodes inserted into the DOM tree in the location of the mission_file_child node. Child nodes could also contain children, but would be a depth limit to protect against circular references in the child files.

jblee123 commented 10 months ago
dmagree commented 10 months ago

...I'd opt for something standard like import or include...

I like that better too.

Are you intending that included files be fully valid mission files in and of themselves?

I wasn't, for the reason that there is a lot of boilerplate on full mission files and it would be somewhat arbitrary what you carry over or not. Prob not the run node. What about origin location? Grid spacing? Certain plugin types like entity interaction or network? I'm not sure where to draw the line, I think it would be pretty arbitrary in the end. Thats why I was leaning towards a method that puts the responsibility on the author to make sure that whats include doesn't wreck the original intent. They are just xml files, and all of the contents will get rolled into the mission file.

For explicitness, consider a msnlib file...

This approach could make what I said above more explicit

I'm assuming the specified files would be searched for in the list of directories specified by SCRIMMAGE_MISSION_PATH.

That was my intent, although I don't know all the ins and outs of that search path either.

We can...unambiguously tell the user what the cycle is.

My graph theory is a little weak. if you can point me to an algorithm or library that would help with this, I'm all ears.

waford commented 5 months ago

I've been working on adding this feature. XML defines a standard for including other XML files in its DOM called XInclude, which can be enabled by including the XInclude namespace in the XML file, e.g. the runscript tag in a mission file might look like: <runscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" name="Straight Mission With XInclude">

Other XML files can then be included with an xi:include tag. For example, to include the definition of an entity in the file "entity1.xml", all that is needed would be <xi:include href="entity1.xml" />

For explicitness, consider a msnlib file...

Subsections of other XML files can be included as well, utilizing XML's XPointers. For example, to include all entity_interaction nodes from a file straight.xml, all you would need is to have the xpointer attribute of the xi:include tag specify this node path: <xi:include href="straight.xml" xpointer="xpointer(/*/entity_interaction)"/>

I'm assuming the specified files would be searched for in the list of directories specified by SCRIMMAGE_MISSION_PATH.

This is a downside of using XInclude, is that the parser will not actively search for files in a specific directory, the resource specified by the href attribute defines the relative path to the included xml file.

My graph theory is a little weak. if you can point me to an algorithm or library that would help with this, I'm all ears.

Not a problem. XInclude already handles inclusion loops, and will fail if it begins to recursively process the same xi:include elements. The full details about inclusion loops are here, but the general rule is that the same xi:include tag can not be included more than once in the same inclusion chain.

This feature is currently implemented in the branch and I've put together a simple example here demonstrating some simple examples of XInclude.

Please feel free to try it out or let me know if Scrimmage needs something a little more specialized!

dmagree commented 2 months ago

Finally was able to try this out. This approach solves the main need, thanks!