JuliaReach / SpaceExParser.jl

Parser for the SpaceEx modeling language in Julia
https://juliareach.github.io/SpaceExParser.jl/
MIT License
7 stars 1 forks source link

Writer for LinearContinuousSystem #46

Closed schillic closed 3 years ago

schillic commented 3 years ago

I am not sure if this fits in the package because it is the opposite of a parser.

I chose the name writesxmodel because there is readsxmodel already.

Example:

julia> A = rand(3, 3) .-0.5
3×3 Matrix{Float64}:
  0.277972  -0.266285   -0.351089
  0.408685  -0.153038   -0.300954
 -0.20927    0.0107524   0.431776

julia> S = @system(x' = Ax)
LinearContinuousSystem{Float64, Matrix{Float64}}([0.27797173780884044 -0.2662850480574015 -0.35108891420605515; 0.40868455933584547 -0.1530378648466495 -0.30095366007442914; -0.2092704508354004 0.01075236731040552 0.4317763365948508])

julia> writesxmodel("test.xml", S)

test.xml (manual line breaks in the flow block for readability):

<?xml version="1.0" encoding="iso-8859-1"?>
<sspaceex xmlns="http://www-verimag.imag.fr/xml-namespaces/sspaceex" version="0.2" math="SpaceEx">
  <component id="system">
    <param name="x1" type="real" d1="1" d2="1" local="false" dynamics="any" controlled="true" />
    <param name="x2" type="real" d1="1" d2="1" local="false" dynamics="any" controlled="true" />
    <param name="x3" type="real" d1="1" d2="1" local="false" dynamics="any" controlled="true" />
    <location id="1" name="loc1">
      <flow>x1' == 0.27797173780884044 * x1 - 0.2662850480574015 * x2 - 0.35108891420605515 * x3 &amp;
 x2' == 0.40868455933584547 * x1 - 0.1530378648466495 * x2 - 0.30095366007442914 * x3 &amp;
 x3' == -0.2092704508354004 * x1 + 0.01075236731040552 * x2 + 0.4317763365948508 * x3</flow>
    </location>
  </component>
</sspaceex>