You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在CPN-Tools中创建可索引且易于迭代的整数Colset?

How to Create an Indexable, Iterable Integer Colset in CPN Tools

Great question! When working with CPN Tools, creating an indexable integer colset that’s easy to iterate over is totally doable with the syntax you’re already considering. Here’s a step-by-step guide to implement it effectively:

1. Define the Indexed Integer Colset

First, you’ll need to declare your colset using the index keyword alongside a range of integers. Start by defining a constant for the upper bound (if you want a fixed range) in your Declaration section:

const n = 10; // Replace 10 with your desired upper limit
colset PH = index ph with 1..n;
  • The index keyword wraps the integer range 1..n into a named colset (PH) that’s explicitly indexable.
  • Each element in PH corresponds directly to an integer from 1 to n—you can reference elements either by their integer value (e.g., 5) or using the index syntax (ph!5) for clearer, more readable model code.

2. Iterate Over the Colset

Once your colset is defined, you can easily iterate over its elements using CPN Tools’ built-in quantifiers like forall or exists in inscriptions or guards. For example:

  • To apply a transition to every element in PH:
    forall k in PH do (my_conversion_transition!k)
    
  • To check if a specific value falls within the colset’s range:
    exists k in PH where k = input_value
    

You can also pass elements directly to your conversion function in arc inscriptions (e.g., my_conversion_function(k) where k is an element of PH).

3. Optional: Create a Reusable Parameterized Colset

If you need multiple indexed integer colsests with different ranges, define a parameterized colset for reusability:

colset INDEX[size: int] = index idx with 1..size;
// Then instantiate it for your use cases:
colset PH = INDEX[10];
colset USER_INDEX = INDEX[25];

This lets you quickly spin up new indexed integer sets without rewriting the core definition each time.

Key Notes

  • Ensure your upper bound (n or size) is a constant—CPN Tools requires colsests to be statically defined, so variables won’t work here.
  • The index syntax doesn’t alter the underlying integer values; it just gives you a named, iterable set that’s easier to reference and maintain in your model.

Hope this helps you set up your indexed integer colset smoothly—feel free to ask if you need further clarification on any part!

内容的提问来源于stack exchange,提问作者Raed Tabani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 02:27:33