
我想对上面的问卷进行建模,我认为这是一个有向无圈图。
我一直在看的两个图书馆是:
我有几个问题是:
这听起来可行吗?还是有更好的方法来模拟这个问题?
发布于 2018-08-18 07:59:08
现实世界的问卷需要将答案保存在某个地方,而外部状态(就像一组键值对)被证明是有用的。在图中存储给定答案的任何尝试(其中每个可能的值都是一个分离的节点)将立即失败,这是一种称为状态爆炸的现象。
然而,获取先前给出的答案,然后使用条件表达式来实现转换,这是一种转义舱口。作为基于自动机的编程的倡导者,我认为的使用在大多数情况下应该局限于输入数据,并且不应该以这种方式检查外部状态,除非期望的行为不能用合理的图来表示。
为了证明它确实可以工作,我在罗斯马洛中实现了它,并将它推到了这个存储库-- https://github.com/lukaszmakuch/so-questionnaire。您可以在这里的编辑器- https://i.stack.imgur.com/uDkh5.png中看到图形的样子。
这是一个完整的工作示例,支持:
下面是它的工作原理:
git clone https://github.com/lukaszmakuch/so-questionnaire.git
cd so-questionnaire/
npm i
npm start
$ question()
'Q1'
$ answer('baz')
undefined
$ question();
'Q6'
$ answer('anything')
undefined
$ answers();
{ Q1: 'baz',
Q2: null,
Q3: null,
Q4: null,
Q5: null,
Q6: 'anything' }
$ back()
undefined
$ question()
'Q1'
$ answer('foo')
undefined
$ question()
'Q2'
$ answer('test')
undefined
$ answers()
{ Q1: 'foo', Q2: 'test', Q3: null, Q4: null, Q5: null, Q6: null }
$ question()
'Q3'
$ answer('bar')
undefined
$ question()
'Q4'
$ answer('fuzz')
undefined
$ question()
'Q6'
$ back()
undefined
$ question()
'Q4'
$ https://stackoverflow.com/questions/51881085
复制相似问题