用pnml中的java代码表示有色Petri网 当我们编写有色Petri网(Cpnet)时,我们可以在PNML中的声明部分使用java代码,比如下面的例子,或者我们也要考虑这一部分的标准? 下面的示例是一个XML表示,但是我们可以用同样的方法在pnml中表示它吗?如果没有,你能帮我怎么做? 谢谢 导入java.util.Iterator; int x=1; 左公共字符串(int i){ 字符串s=“”; 开关(一){ 案例1: s=新字符串(“b”); 打破 案例2: s=新字符串(“c”); 打破 案例3: s=新字符串(“d”); 打破 案例4: s=新字符串(“e”); 打破 案例5: s=新字符串(“f”); 打破 } 返回s; } 公共字符串权限(int i){ 字符串s=“”; 开关(一){ 案例1: s=新字符串(“a”); 打破 案例2: s=新字符串(“b”); 打破 案例3: s=新字符串(“c”); 打破 案例4: s=新字符串(“d”); 打破 案例5: s=新字符串(“e”); 打破 } 返回s; } 公共令牌集lr(int i){ TokenSet tk=新令牌集(新令牌(右(i)); 添加(新令牌(左(i)); 返回tk; } 免费叉子 “a” “b” “c” “d” “e” 吃 认为 1. 2. 3. 4. 5. lr(x) x x getTokenSet().size()0 x=(整数)(getTokenSet().get(0)).getObject() getTokenSet().size()0 lr(x) getTokenSet().size()0 x 拿叉子 布尔值=false; 迭代器it=p1.getTokens().Iterator(); 而(!found&;it.hasNext()){ Token Token=(Token)it.next(); int i=(整数)标记.getObject(); if(p3.getTokens().containsAll(lr(i))){ x=i; 发现=真; } } 发现退货; 放下叉子 返回true; > p>我想我找到了解决办法,我们不能用同样的方式,我们可以使用像 (MaTML的子集)这样的语言来考虑标准。
感谢您的所有评论。您打算如何处理该模型?CPN工具只接受CPNML。我想构建一个工具来生成表示pnml文件中描述的CP Net的java代码,但事实上,我不清楚如何在pnml文件中编写声明部分。我的意思是,我不清楚是否有任何其他方法可以在pnml中编写上述示例中的声明,是否有任何标准?用pnml中的java代码表示有色Petri网 当我们编写有色Petri网(Cpnet)时,我们可以在PNML中的声明部分使用java代码,比如下面的例子,或者我们也要考虑这一部分的标准? 下面的示例是一个XML表示,但是我们可以用同样的方法在pnml中表示它吗?如果没有,你能帮我怎么做? 谢谢 导入java.util.Iterator; int x=1; 左公共字符串(int i){ 字符串s=“”; 开关(一){ 案例1: s=新字符串(“b”); 打破 案例2: s=新字符串(“c”); 打破 案例3: s=新字符串(“d”); 打破 案例4: s=新字符串(“e”); 打破 案例5: s=新字符串(“f”); 打破 } 返回s; } 公共字符串权限(int i){ 字符串s=“”; 开关(一){ 案例1: s=新字符串(“a”); 打破 案例2: s=新字符串(“b”); 打破 案例3: s=新字符串(“c”); 打破 案例4: s=新字符串(“d”); 打破 案例5: s=新字符串(“e”); 打破 } 返回s; } 公共令牌集lr(int i){ TokenSet tk=新令牌集(新令牌(右(i)); 添加(新令牌(左(i)); 返回tk; } 免费叉子 “a” “b” “c” “d” “e” 吃 认为 1. 2. 3. 4. 5. lr(x) x x getTokenSet().size()0 x=(整数)(getTokenSet().get(0)).getObject() getTokenSet().size()0 lr(x) getTokenSet().size()0 x 拿叉子 布尔值=false; 迭代器it=p1.getTokens().Iterator(); 而(!found&;it.hasNext()){ Token Token=(Token)it.next(); int i=(整数)标记.getObject(); if(p3.getTokens().containsAll(lr(i))){ x=i; 发现=真; } } 发现退货; 放下叉子 返回true; > p>我想我找到了解决办法,我们不能用同样的方式,我们可以使用像 (MaTML的子集)这样的语言来考虑标准。 ,java,automation,modeling,petri-net,dining-philosopher,Java,Automation,Modeling,Petri Net,Dining Philosopher,感谢您的所有评论。您打算如何处理该模型?CPN工具只接受CPNML。我想构建一个工具来生成表示pnml文件中描述的CP Net的java代码,但事实上,我不清楚如何在pnml文件中编写声明部分。我的意思是,我不清楚是否有任何其他方法可以在pnml中编写上述示例中的声明,是否有任何标准? <?xml version="1.0" encoding="UTF-8" standalone="no"?> <pnml> <net id="n1"> <im
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<pnml>
<net id="n1">
<import>
<text>import java.util.Iterator;</text>
</import>
<declaration>
<text>int x = 1;
public String left(int i) {
String s = "";
switch (i) {
case 1:
s = new String("b");
break;
case 2:
s = new String("c");
break;
case 3:
s = new String("d");
break;
case 4:
s = new String("e");
break;
case 5:
s = new String("f");
break;
}
return s;
}
public String right(int i) {
String s = "";
switch (i) {
case 1:
s = new String("a");
break;
case 2:
s = new String("b");
break;
case 3:
s = new String("c");
break;
case 4:
s = new String("d");
break;
case 5:
s = new String("e");
break;
}
return s;
}
public TokenSet lr(int i) {
TokenSet tk = new TokenSet(new Token(right(i)));
tk.add(new Token(left(i)));
return tk;
}</text>
</declaration>
<place id="p3">
<graphics>
<position x="475" y="325"/>
</graphics>
<name>
<text>free forks</text>
<graphics>
<offset x="70" y="0"/>
</graphics>
</name>
<initialMarking>
<text>"a"</text>
<text>"b"</text>
<text>"c"</text>
<text>"d"</text>
<text>"e"</text>
</initialMarking>
</place>
<place id="p2">
<graphics>
<position x="325" y="335"/>
</graphics>
<name>
<text>eat</text>
<graphics>
<offset x="50" y="-10"/>
</graphics>
</name>
</place>
<place id="p1">
<graphics>
<position x="325" y="125"/>
</graphics>
<name>
<text>think</text>
<graphics>
<offset x="60" y="-10"/>
</graphics>
</name>
<initialMarking>
<text>1</text>
<text>2</text>
<text>3</text>
<text>4</text>
<text>5</text>
</initialMarking>
</place>
<arc id="o15" source="t5" target="p3">
<expression>
<text>lr(x)</text>
</expression>
<graphics>
<position x="331" y="440"/>
<position x="454" y="341"/>
</graphics>
</arc>
<arc id="o7" source="t5" target="p1">
<expression>
<text>x</text>
</expression>
<graphics>
<position x="325" y="450"/>
<position x="325" y="515"/>
<position x="185" y="515"/>
<position x="185" y="75"/>
<position x="325" y="75"/>
<position x="325" y="99"/>
</graphics>
</arc>
<arc id="o9" source="t4" target="p2">
<expression>
<text>x</text>
</expression>
<graphics>
<position x="325" y="230"/>
<position x="325" y="309"/>
</graphics>
</arc>
<arc id="i17" source="p2" target="t5">
<expression>
<text>getTokenSet().size()>0</text>
</expression>
<expression>
<text>x = (Integer) (getTokenSet().get(0)).getObject()</text>
</expression>
<graphics>
<position x="325" y="361"/>
<position x="325" y="440"/>
</graphics>
</arc>
<arc id="i11" source="p3" target="t4">
<expression>
<text>getTokenSet().size()>0</text>
</expression>
<expression>
<text>lr(x)</text>
</expression>
<graphics>
<position x="453" y="310"/>
<position x="332" y="230"/>
</graphics>
</arc>
<arc id="i13" source="p1" target="t4">
<expression>
<text>getTokenSet().size()>0</text>
</expression>
<expression>
<text>x</text>
</expression>
<graphics>
<position x="325" y="151"/>
<position x="325" y="220"/>
</graphics>
</arc>
<transition id="t4">
<graphics>
<position x="325" y="225"/>
</graphics>
<name>
<text>take forks</text>
<graphics>
<offset x="-70" y="0"/>
</graphics>
</name>
<guard>
<text>boolean found = false;
Iterator it = p1.getTokens().iterator();
while (!found && it.hasNext()) {
Token token = (Token) it.next();
int i = (Integer) token.getObject();
if (p3.getTokens().containsAll(lr(i))) {
x = i;
found = true;
}
}
return found;</text>
</guard>
</transition>
<transition id="t5">
<graphics>
<position x="325" y="445"/>
</graphics>
<name>
<text>put down forks</text>
<graphics>
<offset x="-70" y="0"/>
</graphics>
</name>
<guard>
<text>return true;</text>
</guard>
</transition>
</net>
</pnml>