 |
|
 |
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers, Chris Maunder
The Code Project Co-founder Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers, Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
| Sign In·View Thread·PermaLink | 4.73/5 |
|
|
|
 |
|
 |
For Shopping Cards i want to Generate Unique Serial Number for every card(countless no of cards) what is the solution plz help me
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
They need to have an order or they must be "random"? They have a size limit?
One of the possible solutions is to use GUID.
When GUID is not possible, I generally use a long value, that is get with DateTime.Ticks.Now (or incremented randomically) if both calls are in the same microsecond.
The class code follows, but you only need to call: TicksOrIncrement.GetValue() to use it.
using System;
namespace Pfz.Threading { public static class TicksOrIncrement { private static readonly object fLock = new object(); private static long fLastValue = DateTime.Now.Ticks; private static readonly Random fRandom = new Random(); public static long GetNext() { long ticks = DateTime.Now.Ticks; lock(fLock) { if (ticks <= fLastValue) ticks = fLastValue + 1 + fRandom.Next(1000); fLastValue = ticks; } return ticks; } } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I have this binary heap, and I need to get the index of a particular node. I can do that now by iterating through the array one by one until I find it, its too slow. Are there any faster ways to search? Whats the fastest?
Here is my code:
class NodeHeap { private Node[] m_nodeHeap = new Node[1000000]; private uint m_lastNodeIndex;
public long Count { get { return m_nodeHeap.LongLength - 1; } }
public Node NodeAt(uint index) { return m_nodeHeap[index]; }
public void RemoveAt(uint index) { if (index > m_lastNodeIndex) { throw new ArgumentOutOfRangeException("uint index"); }
SwapNode(ref m_nodeHeap[index], ref m_nodeHeap[m_lastNodeIndex]);
m_nodeHeap[m_lastNodeIndex--] = null;
SiftUp(index); }
public uint IndexOf(Node n) { for (uint i = 1; i <= m_lastNodeIndex; i++) { if (m_nodeHeap[i] == n) return i; }
return 0; }
public void Add(Node n) { m_nodeHeap[++m_lastNodeIndex] = n;
SiftDown(m_lastNodeIndex); }
public void SiftUp(uint index) { if (index >= m_lastNodeIndex) return;
uint next = index;
next *= 2;
if (next > m_lastNodeIndex) return;
if (m_nodeHeap[next].Cost < m_nodeHeap[index].Cost) { if (next != m_lastNodeIndex && m_nodeHeap[next + 1].Cost < m_nodeHeap[next].Cost) { SwapNode(ref m_nodeHeap[++next], ref m_nodeHeap[index]); } else { SwapNode(ref m_nodeHeap[next], ref m_nodeHeap[index]); }
SiftUp(next); } }
public void SiftDown(uint index) { if (index == 1) return;
uint next = index;
next /= 2;
if (m_nodeHeap[next].Cost > m_nodeHeap[index].Cost) { SwapNode(ref m_nodeHeap[next], ref m_nodeHeap[index]); SiftDown(next); } }
public Node RemoveFirst() { Node n = m_nodeHeap[1]; RemoveAt(1); return n; }
private void SwapNode(ref Node a, ref Node b) { Node temp = a; a = b; b = temp; } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Btw, your swap work "oddly", I would expect to swap by index and avoid ref hacks, but w/e.
To search faster, use your heap property. Meaning that, if this is a min heap (looks like one), see if your value is smaller than the current root, and if so, return and go the other way instead (recursively). Alternatively, do the test before recursing, to save method calls.
(btw, are you going to do A* with it? Heap is a good choice for A* IME)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
harold aptroot wrote: Btw, your swap work "oddly", I would expect to swap by index and avoid ref hacks, but w/e.
Sounds like a nice modification.
harold aptroot wrote: see if your value is smaller than the current root, and if so, return and go the other way instead (recursively)
I'm not quite sure what you mean. Are you saying bounds back and forth between the first and last, then second to first, then second to last, ect...?
harold aptroot wrote: (btw, are you going to do A* with it? Heap is a good choice for A* IME)
Yes, and right now it takes too long to find the path in a complex map like a spiral @ with the endnode inside of it.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
CaptainSeeSharp wrote: I'm not quite sure what you mean. Are you saying bounds back and forth between the first and last, then second to first, then second to last, ect...? Not sure what you mean here.. I mean, start at the root, if the value you're searching is smaller than the root then clearly the item is not in the heap - this applies recursively to every sub-heap as well
OTOH, I didn't need that feature (searching by value) in my A* implementation. Why do you need it?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
harold aptroot wrote: I didn't need that feature (searching by value) in my A* implementation. Why do you need it?
I would really like to see how to make mine not need it. When mine gets the nodes around it, it checks to see if they are on the open list (that is where IndexOf is called), and if they are not then it will add whatever nodes not on the open list.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
But surely your heap is sorted by F cost? And if you find a node a second time, the G (and therefore the F) will probably be different since you would have reached it from an other node (since the one you reached it from the first time should be in your closed list)
I used a sparse "grid of grids"-of bits to test membership of open and closed lists (closed "list" was only that grid and no list), a normal grid would be easier but I had huge maps where paths would "usually" stay in roughly 1 "area", which meant that usually only up to 4 entries of the "supergrid" would be used. The whole thing was just a BitArray[,] btw. The "supertile"-size should be a power of 2 and the area divisible by 32 to be efficient this way, like 16x16, or 32x32. Testing membership of open or closed list is then only O(1), at the expense of .. not even all that much memory (just 1 bit per tile and some overhead, and usually only for a subset of tiles).
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I think I get what you are saying. Use a grid (that is the same size of the map) of bits or bools where a value of 1 or true in a particular X,Y coordinate of the bitarray[,] means that it is in the open list? I don't use a closed list by the way, and it works just as well.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello! I have a problem to make a detection, I need to locate multiple objects (people) was planning to use the algorithm of Viola and Jones extended version of Lienhart (included in OpenCV), can I make a massive detection (crowd, each one people) of objects with these algorithms? (I know it is mainly used for face detection) or exist another solution whithin OpenCV?
Can anyone help me? I no need a source code, just help me to choose an algorithm to do this please!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I'm a newbie and would appreciate it if someone could start me off and guide to on how how can you convert algorithm to C# (probability distribution in Wireless LAN)
Algorithm 1 x= Corr GetLocation (n, S, X, P RM) Input: n : Number of samples from each access point. S : Measured signal strength vectors from k access points (S =(s1, ..., sk)). Each si, 1 ≤ i ≤ k is a vector containing n samples from access point i. X : Radio map locations. RM : Radio map, whereRM[a][x](q) represents the pdf of the average of n signal strength samples from access point a at location x ∈ X. Output: The location x ∈ X that maximizes P(x/S). 1: for i = 1..k do 2: Avg(i) ← average(si) 3: end for 4: Max ← 0 5: for l ∈ X do 6: P ←k i=1 Avg( i)+0.5 Avg(i)−0.5 RM[i][x](q) dq 7: if P > Max then 8: x ← l 9: Max ← p 10: end if 11: end for
modified on Wednesday, November 11, 2009 1:28 PM
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
This is more a programming question than an algorithm question. What languages do you know?
Silver member by constant and unflinching longevity.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Just a brief question. In a little demo I've got going I can have up to 300 objects floating around the screen and checking every object against every other object is painfully slow.
Using a quad tree to split the screen up and group the objects greatly speeds up checking for collisions but unfortunately rebuilding the quad tree every frame eats up quite a lot of the performance that you gain from using it.
Does anybody have any idea's on what I could do, bearing in mind that all 300 objects will constantly be moving and are all fairly close together, so trying to only update objects that have moved would cause the entire tree to be jiggled about a little bit, perhaps costing more time that a full rebuild.
My current favourite word is: Sammidge!-SK Genius Game Programming articles start - here[ ^]-
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
why use a tree that is bound to become invalid all the time?
I would see the screen as a 2D matrix (say N*N) with N around typical screen size divided by typical object size (and not larger than say 10), so each object typically spans two rows and two columns. Each screen cell could be represented by a List containing references to the objects that (partially) lie inside it, and a timestamp.
One time step would: - move some objects, checking them against the 2D matrix cells; resulting in possibly removing them from some lists, and possibly adding them to some lists; store current time in cells objects got added to. - then foreach cell marked with current time, check the listed objects for overlap.
Possible optimization: give each object a list of cells it currently is in; this would speed up the removal step.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Alternative solution: re-structure your "tree" and use a radial(gross) test
radial:
if((dist(a,b)^2-RadiusSqrd)<0) { }
(pathagarean therum with a bit of inside/outside circle, with small error...) it is fast.
Gross:
or iterativly restructure your list...
public static int blah(point P, point Q){ if(P.X>Q.x){ return 1;} else if(P.X==Q.x){return 0} else{return-1} }
this way you would only need to "check" against neighbors in the tree structure.
alternativly you could use a float type(but that is basically the radial method of above)
using this method you basically only ever have a few checks,
there is one other way off hand..
I lik eto use the System.Drawing.Region (i forget the name) but it will give the union or difference of two "polygon"(regions) which is on the gpu and crazy fast.. in which case you may be able to do it brute force.. cus it is fast.. if you like this, or need more reference send me a ping and I will scrounge up the code for you.. leaving work --Hurray 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
in the name of god hello how can we solve this problem to find the order of it: T(n)=sqrt(n)*(T(sqrt(n))+n order =? valhamdolelah.
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Ok then I think: T(n) = (n * C)/(e^2) + (n * ln(ln(n))) / ln(2)
edit: that would be O(n log(log n)) I think
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |