-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse life-like automata rules. #1
base: master
Are you sure you want to change the base?
Conversation
Hi @Sedictious, that's a good idea. However, the standard game of life is known to be the "hello world" of ABM, and modelers usually check it to understand how the API works. So, I'd keep this model as simple as possible, i.e., only implementing the standard and more widespread scenario. Thus, you could push this more general solution into a new repository (as a new plugin). Perhaps calling it Regarding the parser. Why do we need to pass a command (string) here? |
@cardinot I opened a new repo here! I decided to go with the B/S notation since it is the most widespread (and hopefully straight-forward). Even if I change the input to integers, I'm afraid there's still no way of getting rid of the parser since, contrary to Elementary Automata rules, there's no single valid range . For example: in its current form, the |
Excellent. I'll check it soon. 👍
Some people use S/B, others use int/int. Anyway, the notation is ok. My concern is with the extra code and edge cases introduced by that.
Yes, you'd still have to check if the integer (rule) is valid. However, it would save you from extracting the integers from a string, and from checking if the string is in the right format, which is usually error-prone and may involve several extra edge cases. Thus, you could replace "pluginAttributesScope": [ {"rules": "string"} ], by "pluginAttributesScope": [
{"birth": "int[0,max]"},
{"survival": "int[0,max]"}
], In this way, you can assume/trust that your Then, in your code, it might be convenient to avoid extra loops (e.g., the function |
@cardinot I'm not opposed to the idea, but there is one particular edge case that is actually harder to address. Take for example the following:
Oh yes, I suspected that my previous solution was sub-optimal so I used a single bitstream to represent the rulestring and while I didn't time the difference, I can see a significant speed boost. I was also wondering: My current implementation silently ignores any occurrence of |
As this is the only edge case, you could use My main concern is with the formatted string. Considering that That being said, I think there are two potential solutions: "pluginAttributesScope": [
{"birth": "int[0,max]"},
{"survival": "int[-1,max]"}
], or "pluginAttributesScope": [
{"birth": "non-empty-string"},
{"survival": "string"}
], In the second case, you would just have to extract the integer from the string. Despite the edge case for an "empty survival". I would go for the first solution because it lets the GUI aware that just numbers should be accepted (QSpinBox), which has two advantages: 1) simplifies the code as you can assume that the model will only be initialized if the inputs are valid integers; 2) explicitly tells the user that the input should be an integer (QSpinBox). Then, the model would be responsible for the data validation only (instead of type+data validation). However, it's up to you; both solutions should be fine 😄 |
@cardinot I ended up going with the former, since it allowed me to get rid of most ugly check conditionals. Do you think that it's worth it to check whether the sequence is monotonically increasing (e.g. |
I agree with you. both I had a very quick look at your code. A few comments:
int input = 123456;
do { // we need a do-while to handle the case in which input=0
int digit = input % 10;
// do something with `digit`
input /= 10;
} while(input);
|
You're right, and contiguous allocation (probably) won't have any affect on performance.
I didn't mind this at first, since this is only called on initialization anyway, but I agree |
Thanks @Sedictious. 👍
|
I think I made all the necessary changes!
I briefly touched on it before:
I ended up cutting the size down to 9 |
Looks good. 👌 |
@cardinot Done! |
So I went ahead and implemented the same thing I did for Elementary Cellular Automata. The parser is admittedly a bit chunky and inelegant, so I'll add the respective docs once I'm done with the fixes.
On the plus side, the result is more interesting. Here is an automaton following the replicator rule (B1357/S1357)