-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
341 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,214 @@ | ||
<?xml version="1.0"?> | ||
<pnml xmlns="http://www.pnml.org/version-2009/grammar/pnml"><net id="Referendum-COL-0010" type="http://www.pnml.org/version-2009/grammar/symmetricnet"><page id="DocumentDefaultPage"><place id="ready"><name><text>ready</text></name><type><text>Dot</text><structure><usersort declaration="dot"/></structure></type><hlinitialMarking><text>1'(dot)</text><structure><numberof><subterm><numberconstant value="1"><positive/></numberconstant></subterm><subterm><dotconstant/></subterm></numberof></structure></hlinitialMarking></place><place id="voted_no"><name><text>voted_no</text></name><type><text>Voters</text><structure><usersort declaration="Voters"/></structure></type></place><place id="voted_yes"><name><text>voted_yes</text></name><type><text>Voters</text><structure><usersort declaration="Voters"/></structure></type></place><place id="voting"><name><text>voting</text></name><type><text>Voters</text><structure><usersort declaration="Voters"/></structure></type></place><transition id="start"><name><text>start</text></name></transition><transition id="no"><name><text>no</text></name></transition><transition id="yes"><name><text>yes</text></name></transition><arc id="arc10" source="start" target="voting"><hlinscription><text>1'[(Voters.all)]</text><structure><numberof><subterm><numberconstant value="1"><positive/></numberconstant></subterm><subterm><all><usersort declaration="Voters"/></all></subterm></numberof></structure></hlinscription></arc><arc id="arc11" source="ready" target="start"><hlinscription><text>1'(dot)</text><structure><numberof><subterm><numberconstant value="1"><positive/></numberconstant></subterm><subterm><dotconstant/></subterm></numberof></structure></hlinscription></arc><arc id="arc12" source="no" target="voted_no"><hlinscription><text>1'[(v)]</text><structure><numberof><subterm><numberconstant value="1"><positive/></numberconstant></subterm><subterm><variable refvariable="varv"/></subterm></numberof></structure></hlinscription></arc><arc id="arc13" source="voting" target="no"><hlinscription><text>1'[(v)]</text><structure><numberof><subterm><numberconstant value="1"><positive/></numberconstant></subterm><subterm><variable refvariable="varv"/></subterm></numberof></structure></hlinscription></arc><arc id="arc14" source="yes" target="voted_yes"><hlinscription><text>1'[(v)]</text><structure><numberof><subterm><numberconstant value="1"><positive/></numberconstant></subterm><subterm><variable refvariable="varv"/></subterm></numberof></structure></hlinscription></arc><arc id="arc15" source="voting" target="yes"><hlinscription><text>1'[(v)]</text><structure><numberof><subterm><numberconstant value="1"><positive/></numberconstant></subterm><subterm><variable refvariable="varv"/></subterm></numberof></structure></hlinscription></arc></page><name><text>Referendum-COL-010</text></name><declaration><structure><declarations><namedsort id="Voters" name="Voters"><cyclicenumeration><feconstant id="Voters1" name="1"/><feconstant id="Voters2" name="2"/><feconstant id="Voters3" name="3"/><feconstant id="Voters4" name="4"/><feconstant id="Voters5" name="5"/><feconstant id="Voters6" name="6"/><feconstant id="Voters7" name="7"/><feconstant id="Voters8" name="8"/><feconstant id="Voters9" name="9"/><feconstant id="Voters10" name="10"/></cyclicenumeration></namedsort><variabledecl id="varv" name="v"><usersort declaration="Voters"/></variabledecl><namedsort id="dot" name="Dot"><dot/></namedsort></declarations></structure></declaration></net></pnml> | ||
<pnml xmlns="http://www.pnml.org/version-2009/grammar/pnml"> | ||
<net id="Referendum-COL-0010" type="http://www.pnml.org/version-2009/grammar/symmetricnet"> | ||
<page id="DocumentDefaultPage"> | ||
<place id="ready"> | ||
<name> | ||
<text>ready</text> | ||
</name> | ||
<type> | ||
<text>Dot</text> | ||
<structure> | ||
<usersort declaration="dot"/> | ||
</structure> | ||
</type> | ||
<hlinitialMarking> | ||
<text>1'(dot)</text> | ||
<structure> | ||
<numberof> | ||
<subterm> | ||
<numberconstant value="1"> | ||
<positive/> | ||
</numberconstant> | ||
</subterm> | ||
<subterm> | ||
<dotconstant/> | ||
</subterm> | ||
</numberof> | ||
</structure> | ||
</hlinitialMarking> | ||
</place> | ||
<place id="voted_no"> | ||
<name> | ||
<text>voted_no</text> | ||
</name> | ||
<type> | ||
<text>Voters</text> | ||
<structure> | ||
<usersort declaration="Voters"/> | ||
</structure> | ||
</type> | ||
</place> | ||
<place id="voted_yes"> | ||
<name> | ||
<text>voted_yes</text> | ||
</name> | ||
<type> | ||
<text>Voters</text> | ||
<structure> | ||
<usersort declaration="Voters"/> | ||
</structure> | ||
</type> | ||
</place> | ||
<place id="voting"> | ||
<name> | ||
<text>voting</text> | ||
</name> | ||
<type> | ||
<text>Voters</text> | ||
<structure> | ||
<usersort declaration="Voters"/> | ||
</structure> | ||
</type> | ||
</place> | ||
<transition id="start"> | ||
<name> | ||
<text>start</text> | ||
</name> | ||
</transition> | ||
<transition id="no"> | ||
<name> | ||
<text>no</text> | ||
</name> | ||
</transition> | ||
<transition id="yes"> | ||
<name> | ||
<text>yes</text> | ||
</name> | ||
</transition> | ||
<arc id="arc10" source="start" target="voting"> | ||
<hlinscription> | ||
<text>1'[(Voters.all)]</text> | ||
<structure> | ||
<numberof> | ||
<subterm> | ||
<numberconstant value="1"> | ||
<positive/> | ||
</numberconstant> | ||
</subterm> | ||
<subterm> | ||
<all> | ||
<usersort declaration="Voters"/> | ||
</all> | ||
</subterm> | ||
</numberof> | ||
</structure> | ||
</hlinscription> | ||
</arc> | ||
<arc id="arc11" source="ready" target="start"> | ||
<hlinscription> | ||
<text>1'(dot)</text> | ||
<structure> | ||
<numberof> | ||
<subterm> | ||
<numberconstant value="1"> | ||
<positive/> | ||
</numberconstant> | ||
</subterm> | ||
<subterm> | ||
<dotconstant/> | ||
</subterm> | ||
</numberof> | ||
</structure> | ||
</hlinscription> | ||
</arc> | ||
<arc id="arc12" source="no" target="voted_no"> | ||
<hlinscription> | ||
<text>1'[(v)]</text> | ||
<structure> | ||
<numberof> | ||
<subterm> | ||
<numberconstant value="1"> | ||
<positive/> | ||
</numberconstant> | ||
</subterm> | ||
<subterm> | ||
<variable refvariable="varv"/> | ||
</subterm> | ||
</numberof> | ||
</structure> | ||
</hlinscription> | ||
</arc> | ||
<arc id="arc13" source="voting" target="no"> | ||
<hlinscription> | ||
<text>1'[(v)]</text> | ||
<structure> | ||
<numberof> | ||
<subterm> | ||
<numberconstant value="1"> | ||
<positive/> | ||
</numberconstant> | ||
</subterm> | ||
<subterm> | ||
<variable refvariable="varv"/> | ||
</subterm> | ||
</numberof> | ||
</structure> | ||
</hlinscription> | ||
</arc> | ||
<arc id="arc14" source="yes" target="voted_yes"> | ||
<hlinscription> | ||
<text>1'[(v)]</text> | ||
<structure> | ||
<numberof> | ||
<subterm> | ||
<numberconstant value="1"> | ||
<positive/> | ||
</numberconstant> | ||
</subterm> | ||
<subterm> | ||
<variable refvariable="varv"/> | ||
</subterm> | ||
</numberof> | ||
</structure> | ||
</hlinscription> | ||
</arc> | ||
<arc id="arc15" source="voting" target="yes"> | ||
<hlinscription> | ||
<text>1'[(v)]</text> | ||
<structure> | ||
<numberof> | ||
<subterm> | ||
<numberconstant value="1"> | ||
<positive/> | ||
</numberconstant> | ||
</subterm> | ||
<subterm> | ||
<variable refvariable="varv"/> | ||
</subterm> | ||
</numberof> | ||
</structure> | ||
</hlinscription> | ||
</arc> | ||
</page> | ||
<name> | ||
<text>Referendum-COL-010</text> | ||
</name> | ||
<declaration> | ||
<structure> | ||
<declarations> | ||
<namedsort id="Voters" name="Voters"> | ||
<cyclicenumeration> | ||
<feconstant id="Voters1" name="1"/> | ||
<feconstant id="Voters2" name="2"/> | ||
<feconstant id="Voters3" name="3"/> | ||
<feconstant id="Voters4" name="4"/> | ||
<feconstant id="Voters5" name="5"/> | ||
<feconstant id="Voters6" name="6"/> | ||
<feconstant id="Voters7" name="7"/> | ||
<feconstant id="Voters8" name="8"/> | ||
<feconstant id="Voters9" name="9"/> | ||
<feconstant id="Voters10" name="10"/> | ||
</cyclicenumeration> | ||
</namedsort> | ||
<variabledecl id="varv" name="v"> | ||
<usersort declaration="Voters"/> | ||
</variabledecl> | ||
<namedsort id="dot" name="Dot"> | ||
<dot/> | ||
</namedsort> | ||
</declarations> | ||
</structure> | ||
</declaration> | ||
</net> | ||
</pnml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright 2020. LAAS-CNRS, Vertics. All rights reserved. | ||
// Use of this source code is governed by the CeCILL-B license | ||
// that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
|
||
"github.com/dalzilio/mcc/corenet" | ||
"github.com/dalzilio/mcc/hlnet" | ||
"github.com/dalzilio/mcc/pnml" | ||
|
||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// tinaCmd takes a PNML model for a high level net, with a .pnml extension, and | ||
// generates a P/T net equivalent in the .net format used in TINA. | ||
var tinaCmd = &cobra.Command{ | ||
Use: "tina -i file.pnml", | ||
Short: "generates a P/T net file in .net format", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
tinaConvert(tinaFileName) | ||
}, | ||
} | ||
|
||
var tinaFileName string | ||
var tinaOutFileName string | ||
var tinaUseName bool | ||
var tinaUseComplexPNames bool | ||
|
||
var tinaLogger *log.Logger | ||
|
||
func init() { | ||
RootCmd.AddCommand(tinaCmd) | ||
tinaCmd.Flags().StringVarP(&tinaFileName, "file", "i", "", "name of the input file (.pnml)") | ||
tinaCmd.Flags().StringVarP(&tinaOutFileName, "out", "o", "", "basename of the output file (without extension, default to input file basename) or - for stdout") | ||
tinaCmd.Flags().BoolVar(&tinaUseName, "name", false, "use PNML (document) name for the output file") | ||
|
||
tinaLogger = log.New(os.Stderr, "MCC TINA:", 0) | ||
} | ||
|
||
func tinaConvert(filename string) { | ||
// we capture panics so that that we don't pollute stdout if something goes wrong | ||
defer func() { | ||
if r := recover(); r != nil { | ||
tinaLogger.Println("Error in generation: cannot compute") | ||
os.Exit(1) | ||
} | ||
}() | ||
|
||
if filename == "" { | ||
tinaLogger.Println("Bad command line! Input file mandatory. Use option -i") | ||
os.Exit(1) | ||
return | ||
} | ||
|
||
if filepath.Ext(filename) != ".pnml" { | ||
tinaLogger.Println("Wrong file extension!") | ||
os.Exit(1) | ||
return | ||
} | ||
|
||
xmlFile, err := os.Open(filename) | ||
if err != nil { | ||
tinaLogger.Println("Error opening file:", err) | ||
os.Exit(1) | ||
return | ||
} | ||
defer xmlFile.Close() | ||
|
||
decoder := pnml.NewDecoder(xmlFile) | ||
var p = new(pnml.Net) | ||
err = decoder.Build(p) | ||
if err != nil { | ||
tinaLogger.Println("Error decoding PNML file:", err) | ||
os.Exit(1) | ||
return | ||
} | ||
|
||
// compute name of the output file. There are three possible cases. | ||
_, file := filepath.Split(filename) | ||
outfile := tinaOutFileName | ||
if outfile == "" { | ||
outfile = file[0 : len(file)-len(".pnml")] | ||
} | ||
if tinaUseName { | ||
outfile = p.Name | ||
} | ||
|
||
p.SetSliced(true) | ||
p.SetVerbose(pnml.QUIET) | ||
// p.SetVerbose(pnml.MINIMAL) | ||
// set the semantic of "overflowing" enumeration types | ||
p.SetFES(false) | ||
hl, err := hlnet.Build(p) | ||
if err != nil { | ||
hlnetLogger.Println("Error decoding PNML file:", err) | ||
os.Exit(1) | ||
return | ||
} | ||
|
||
cn := corenet.Build(p, hl) | ||
|
||
var out *os.File | ||
if outfile == "-" { | ||
out = os.Stdout | ||
} else { | ||
out, err = os.Create(outfile + ".net") | ||
if err != nil { | ||
hlnetLogger.Println("Error creating result file: ", err) | ||
os.Exit(1) | ||
return | ||
} | ||
defer out.Close() | ||
} | ||
w := bufio.NewWriter(out) | ||
cn.Write(w) | ||
w.Flush() | ||
} |