c# - Efficient search for generic objects without predecessors -
i have genobjectlist
of generic objects , openlist
of generic objects still needs used. of generic objects depend on each other. generic objects of predecessors used used. implementation use following:
var genobjectlist = // generic objects somewhere var openlist = new list<genobject>(genobjectlist); var closedlist = new list<genobject>(); var rand = new random(); while (openlist.count != 0) { var candidatelist = openlist.findall( t => t.predecessors.where(p => genobjectlist.contains(p)).intersect(closedlist).count() == t.predecessors.count(p => genobjectlist.contains(p))); var choosengenobject = candidatelist[rand.next(0, candidatelist.count)]; openlist.remove(choosengenobject); closedlist.add(choosengenobject); // generic object }
the part find candidatelist
seems inefficient if genobjectlist
contains 300 entries.
i'm looking better implementation achieve same behaviour. ideas?
edit: clarify misleading use of task
: question not c# tasks , methods, on generic objects have precedence constraints , how handle them. edited post make clear.
edit2: advise use topological sorting right way. i'm looking sth. described 'non deterministic topological sorting'. depth first search implementation e.g. quickgraph
1 gets same topological sorting if it's not unique. i'm looking implementation uses random number tie-breaker , has chance create topological sorting's.
Comments
Post a Comment