由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教一个有向图的算法
相关主题
一个有向图问题请教:未名首页打不开
最新的MS面试题 (转载)gmail当了?
问个图的问题请教一道C语言的题目
怎么非ASCII字符就过滤不了呢?[Perl]请教一个系统设计问题
Question: Send the message to Database using ASP but without opening a window?a question about std::stack
c++里面有什么Container插入是最快的?Anyone ever ran into a "fatal error LNK1168" in MS VS studi
how to turn off "ActiveX Control Test Container"?Share a video about design
C++可完全取代C吗?Depth-First-Search (转载)
相关话题的讨论汇总
话题: s2话题: pop话题: s1话题: nodes话题: so
进入Programming版参与讨论
1 (共1页)
l*****a
发帖数: 135
1
请教一个算法,请看附图,如果有一个有向图,每个点代表一个任务,任务有先后关系。
我要产生一个集合K, K中的每个元素代表了一个所有任务的状态。
(比如abcd代表“abcd这四个任务完成,其他的没完成”这一状态,并且abcd是符合图
中的先后关系的。又比如没有状态af,因为根据图中的关系,不可有“af这两个任务完
成,而其他的任务没完成”这一状态。)
请问最好的算法是什么?有python的package吗?
我能想到的是写个constraint programming(CP) model,让CP solver去解决,是不是
太傻了?
p***o
发帖数: 1252
2
Check closure problem on wiki. Most likely you don't need CP and
a network flow solver is good enough.

系。

【在 l*****a 的大作中提到】
: 请教一个算法,请看附图,如果有一个有向图,每个点代表一个任务,任务有先后关系。
: 我要产生一个集合K, K中的每个元素代表了一个所有任务的状态。
: (比如abcd代表“abcd这四个任务完成,其他的没完成”这一状态,并且abcd是符合图
: 中的先后关系的。又比如没有状态af,因为根据图中的关系,不可有“af这两个任务完
: 成,而其他的任务没完成”这一状态。)
: 请问最好的算法是什么?有python的package吗?
: 我能想到的是写个constraint programming(CP) model,让CP solver去解决,是不是
: 太傻了?

h*******u
发帖数: 15326
3
你这个没定义清楚。比如a和b无关,ab是不是等价ba?在K里面你想怎么处理?

系。

【在 l*****a 的大作中提到】
: 请教一个算法,请看附图,如果有一个有向图,每个点代表一个任务,任务有先后关系。
: 我要产生一个集合K, K中的每个元素代表了一个所有任务的状态。
: (比如abcd代表“abcd这四个任务完成,其他的没完成”这一状态,并且abcd是符合图
: 中的先后关系的。又比如没有状态af,因为根据图中的关系,不可有“af这两个任务完
: 成,而其他的任务没完成”这一状态。)
: 请问最好的算法是什么?有python的package吗?
: 我能想到的是写个constraint programming(CP) model,让CP solver去解决,是不是
: 太傻了?

b***e
发帖数: 1419
4
Seems it's just a queue construct starting from the super set of roots. For
your example, start with:
{{}|{a,b}, {a}|{b}, {b}|{a}, {a,b}|{}}
Note we use S1|S2 to denote a state where the nodes in S1 must appear and
nodes in S2 must not appear in any future extension.
Pop {}|{a,b}. You can not reach more with empty starting set, so this is it.
Pop {a}|{b}, which means a is in and b is out. This state only reaches {a,c
}|{b}, so we push that in.
Pop {b}|{a}. This state doesn't reach anywhere, so this is it.
Pop {a,b}|{}. This state reaches {a,b,c}{}, so we push it.
Pop {a,c}|{b}, which we just added. This reaches no further where.
Pop {a,b,c}|{}, this reaches the following:
- {a,b,c,d}|{e}
- {a,b,c,e}|{d}
- {a,b,c,d,e}|{}
So we push all them in the queue.
{a,b,c,d}|{e} pops and is final.
{a,b,c,e}|{d} is pops and is final.
{a,b,c,d,e}|{} pops and reaches {a,b,c,d,e,f}|{}.
{a,b,c,d,e,f}|{} pops and is final.
The queue is empty, so we are done.
So all we need is to understand what're the reachable states from S1|S2.
Here's the semantics:
From the original graph, remove all the nodes in S2 as well as any nodes
that are reachable from any nodes in S2. Let A = {all the nodes in the
remaining graphs whose upstream dependencies is a subset of S1}. Let SA be
the super set of A. Then all the reachable state from S1|S2 is:
{S1+A1|S2+A2 | A1 <- SA, A2 = A - A1}
where we use + for set union, and - for set diff.

系。

【在 l*****a 的大作中提到】
: 请教一个算法,请看附图,如果有一个有向图,每个点代表一个任务,任务有先后关系。
: 我要产生一个集合K, K中的每个元素代表了一个所有任务的状态。
: (比如abcd代表“abcd这四个任务完成,其他的没完成”这一状态,并且abcd是符合图
: 中的先后关系的。又比如没有状态af,因为根据图中的关系,不可有“af这两个任务完
: 成,而其他的任务没完成”这一状态。)
: 请问最好的算法是什么?有python的package吗?
: 我能想到的是写个constraint programming(CP) model,让CP solver去解决,是不是
: 太傻了?

l*****a
发帖数: 135
5
ab == ba,代表了一个“ab两个任务都完成了”这么一个状态

【在 h*******u 的大作中提到】
: 你这个没定义清楚。比如a和b无关,ab是不是等价ba?在K里面你想怎么处理?
:
: 系。

l*****a
发帖数: 135
6
thanks for replying!

For
it.
,c

【在 b***e 的大作中提到】
: Seems it's just a queue construct starting from the super set of roots. For
: your example, start with:
: {{}|{a,b}, {a}|{b}, {b}|{a}, {a,b}|{}}
: Note we use S1|S2 to denote a state where the nodes in S1 must appear and
: nodes in S2 must not appear in any future extension.
: Pop {}|{a,b}. You can not reach more with empty starting set, so this is it.
: Pop {a}|{b}, which means a is in and b is out. This state only reaches {a,c
: }|{b}, so we push that in.
: Pop {b}|{a}. This state doesn't reach anywhere, so this is it.
: Pop {a,b}|{}. This state reaches {a,b,c}{}, so we push it.

q*c
发帖数: 9453
7
topological sorting.

系。

【在 l*****a 的大作中提到】
: 请教一个算法,请看附图,如果有一个有向图,每个点代表一个任务,任务有先后关系。
: 我要产生一个集合K, K中的每个元素代表了一个所有任务的状态。
: (比如abcd代表“abcd这四个任务完成,其他的没完成”这一状态,并且abcd是符合图
: 中的先后关系的。又比如没有状态af,因为根据图中的关系,不可有“af这两个任务完
: 成,而其他的任务没完成”这一状态。)
: 请问最好的算法是什么?有python的package吗?
: 我能想到的是写个constraint programming(CP) model,让CP solver去解决,是不是
: 太傻了?

1 (共1页)
进入Programming版参与讨论
相关主题
Depth-First-Search (转载)Question: Send the message to Database using ASP but without opening a window?
C# no output of ConsoleWriteLine Visual Studio 2013 (转载)c++里面有什么Container插入是最快的?
问个算法问题how to turn off "ActiveX Control Test Container"?
Re: 请教一道题目C++可完全取代C吗?
一个有向图问题请教:未名首页打不开
最新的MS面试题 (转载)gmail当了?
问个图的问题请教一道C语言的题目
怎么非ASCII字符就过滤不了呢?[Perl]请教一个系统设计问题
相关话题的讨论汇总
话题: s2话题: pop话题: s1话题: nodes话题: so