Beispiel #1
0
		public IEnumerable<Tuple<int, Tuple<int,int>>> edges(state state)
		{
			var queue = new pqueue<int, Tuple<int, int>>(0, new Tuple<int, int>(-1, -1));//TODO: test cratio

			int ll = int.MaxValue;
			foreach(Tuple<int,int> t in expand(state))
			{
				queue.enqueue(model.edge_cost(t.Item1, t.Item2, state), t);
				ll = t.Item1;
			}

			if (ll != 1)
			{
				yield return new Tuple<int, Tuple<int, int>>(model.edge_cost(1, 0, state), new Tuple<int, int>(1, 0));
			}

			while (queue.count > 0)
			{
				yield return queue.dequeue();
			}
		}
Beispiel #2
0
		private void subpath(int cpos, ref int cend)
		{
			var queue = new pqueue<int, int>(0, 0);
			var cendqueue = new pqueue<int, int>(0, 0);

			foreach(KeyValuePair<int, state> kvp in tree[cpos])
			{
				queue.enqueue(kvp.Value.bitcost, kvp.Value.position);
			}

			while (!queue.empty)
			{
				cpos = queue.dequeue().Item2;

				if (!closed[cpos])
				{
					foreach (KeyValuePair<int, state> kvp in tree[cpos])
					{
						int roffs = kvp.Key;
						state cstate = kvp.Value;

						if (cstate.bitcost <= cost[cpos] + cost_tolerance)
						{
							foreach (Tuple<int, Tuple<int, int>> ccostedge in edge.edges(cstate))
							{
								int cedgecost = ccostedge.Item1;
								Tuple<int, int> cedge = ccostedge.Item2;

								if (!closed[cstate.position + cedge.Item1] && cstate.bitcost + cedgecost <= cost[cstate.position + cedge.Item1] + cost_tolerance)
								{
									var dstate = new state(cstate, ccostedge);

									int tl = dstate.position;
									while (tl > cstate.position)
									{
										cost[tl] = dstate.bitcost < cost[tl] ? dstate.bitcost : cost[tl];
										tl--;
									}

									if (!tree[dstate.position].ContainsKey(dstate.roffs))
									{
										tree[dstate.position].Add(dstate.roffs, dstate);
									}
									else if (dstate.bitcost < tree[dstate.position][dstate.roffs].bitcost || (dstate.bitcost == tree[dstate.position][dstate.roffs].bitcost && dstate.steps < tree[dstate.position][dstate.roffs].steps))
									{
										tree[dstate.position][dstate.roffs] = dstate;
									}

									if (dstate.position < cend)
									{
										queue.enqueue(dstate.bitcost, dstate.position);
									}
									else if (dstate.position == cend)
									{
										cendqueue.enqueue(dstate.bitcost, dstate.position);
									}
									else if (dstate.position > cend)
									{
										if (!cendqueue.empty)
										{
											var t = cendqueue.dequeue();
											queue.enqueue(t.Item1, t.Item2);
										}

										while (!cendqueue.empty)
										{
											cendqueue.dequeue();
										}

										cend = dstate.position;
										cendqueue.enqueue(dstate.bitcost, dstate.position);
									}
									/*else
									{
										throw new Exception("head blown");
									}*/
								}
							}
						}
					}
					closed[cpos] = true;
				}
			}
		}