|
The first 8 bits are a serial number of the read unit. The data is records, read as strings out of the unit. I am a the moment not splitting them just saving them as one file, this is where the spec is a little flaky and I am trying to have an answer ready if needed. If I use the method I was using the String.split method, I need to check the first 8 bits against a stored list, I was thinking of using rich text boxes to store the split reading in for a test and then using strings for the actual program. Firstly I need to declare an array of strings which in theory could be 1024 in size.
new string[] Serial_Numbers ={};
This I'm guessing from the green underlining is wrong but....
Glenn
|
|
|
|
|
string[] Serial_Numbers = something;
Ok, I still have absolutely no idea what the problem is or how to solve it, though
|
|
|
|
|
You would normally declare something like this as
string[] serial_numbers = new string[] {}; Note, however, that you've just declared a zero length array, so you would have to resize it (which isn't the most efficient operation) whenever you want to use it. There are many more efficient ways to save the data - and which one you choose depends on what you want to do with it. You could use a List<string> or a Dictionary of strings and readings - which one you choose depends on what the ultimate purpose is of the readings.
|
|
|
|
|
Hmmm, the evil gods Malloc() & Calloc(), but I have already discovered that. The ultimate goal is to split the readings into separate files from the text property of a text box ie the box has output from the hand held in one rtb I was looking for a way to split the contents up. If the readings are say 12345678|AAA|BBBB|CCCCCC the next reading is 23456781|AAA|BBBB|CCCC at the moment the file is created with all the readings in one place. What I'm trying to is split up the data to separate files as the spec does say to do it that way but I can see problems with it if don't have a method, if I create the string array with the total number of records read from the unit that would get around that problem. If I use substring() as below:
foreach (string subString in rtbTestBox.Text.Split('\n'))
{
foreach (string subStringSerNo in subString.Split('|'))
{
if (subStringSerNo.Length == 7)
{
Serial_Numbers[serialNumberIndex] = subString;
MessageBox.Show(subString);
MessageBox.Show("Yaowwwser!!!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
serialNumberIndex++;
}
}
and it should give me an array of readings which I can the search for differences in the serial number. If I then have the array of strings, the serial number is different I can place it in a different string if it's the same just append it.
Am I making any sense in my caffeine addled state!
Glenn
|
|
|
|
|
I see a few issues with this design.
First of all, you are using the RTB as the datasource - you really should use a proper structure for the data - you can add the data from this to your UI if you need, but you should start off with the idea that the data is the important thing (this also simplifies you saving out the data).
Secondly - if you need to display the data, you will find it easier to display it in a ListBox. Adding items into a ListBox takes a lot less time than adding data at the end of a large RTB.
I would be tempted to have a structure that represented a single reading, and then create a Dictionary using the serial number as the key, and a List of these readings as the value. That way, you can iterate over the Dictionary and save out the values to separate files.
|
|
|
|
|
Good advice.
When using a list box he may store the numerical serial number as item data.
|
|
|
|
|
Sorry didn't see your reply, I was messing with a test app. The issue I have knocked up I have some test data in a list box.
|
|
|
|
|
No need to say sorry. It's not a chat here.
If you already have a list box, you may use my suggestion. Then you can identify the device strings by querying the item data (e.g. write all strings for a specific device to a file).
|
|
|
|
|
After a bit of fiddling, I have a list box I can add the data to
1111111|16:11:52|08-10-12|0|0|00a8
now this is a sample returned from the unit, The serial number of what I am trying to sort are
11111111 I would like to get an opinion on whether or not using an array of strings the size of the total number of records on the unit is a good idea bearing in mind I have no idea what PC it is going to be run on. Here's hoping what I sent is good enough (one file)! (before you say it I know full well Hope & Pray are not viable options! )
Glenn
|
|
|
|
|
If you add such strings to a list box you already have an array of strings. You can use the Find() method to find strings that begin with a specific serial numbers. You can implement a sort function to sort by the serial numbers.
I'm using C++ and did not have experience with .NET. Using MFC or Windows API functions, each item of a list box can be assigned a user data value. When setting this item data to the serial number, the list can be searched and sorted by these values which is much faster than searching/sorting using the strings (item text).
Performance depends on the max. number of items. You may raise a new question about this. May be someone else has experience with large list boxes. I think a few thousand items should be no problem.
|
|
|
|
|
Thanks, in the actual application I am updating the actual RTB on the fly which doesn't seem to be causing any problems yet I will look at changing to a list box. The issue I am having at the moment is how to split the data up if I need to (I wish I could call the guy testing it and ask him, several problems involving time zones, company politics, project ownership, pointy haired business practice , etc.) Really I just need to read the first 8(ish, in spec, 7 on dev. board)
bytes and if they are different from ones already read create a separate store for them.
After some though (& coffee)
Step 1 use total number of readings to create a string array.
2 read the RTB string split using substring for a \n
3 read the first 8 (or 7 bytes) if its new place in a list. if not add to list
4 repeat 2 & 3 until total number string read in 1 are reached.
5 Save out each of the populated strings and free up resources. Sorry about this reply got grabbed to something else in the office!
Glenn
|
|
|
|
|
I like the ability to downvote, I do it myself on occasion. Then again, these are valid questions to ask, one would actually assume that information to be part of the question.
The reason I'm making a point of it, is because you're not a respectable downvoter. You're a two-voter! The easy way of coloring someone gray, without losing a point yerself.
Grow a spine, and tell the man why you think his answer sucks
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
hi guys . i ask my qustion very fast . i just need to help me . ty for any help.
my qustion is that , i have made a bfs solver class that solve the puzzle 8 with bfs algorithm .
what im doing its like this .
1 - node class >> contain some info
2- bfs solver class
2-1 : Qeue Neede .
2-2 : enqeue the first node (initial state) << its parent .
2-3 : check if its the Goal Or not (if its not go to next )
2-4 : find the empty tile and see if you can exchange any tile with it .
2-5 : any change w'll make a child node . of that parent
2-6 : deqeue the parent node.
2-6 : check if the child node of the parent is in the qeue (if is not then enqeue the child node and put a parent label on it). jump to the (2-3)
is that algorithm working well , i have test it and it really work fine , the problem its here that it dosnt work if i played too much with the tile and chaneged them around . it works fine in small problem like {1,2,3,5,4,6,0,7,8} or sth like this .
and it gave me an error stackoverflow in big problems like {8,0,4,2,3,1,6,7,5} i dont know what should i do to prevent this error but i just know that my codes work fine .
im writing my code with c#.net . using a node class and bfs solver class.
i can put some parts of my code if you neede to see what im doing .
i'll appriciate any help .
modified 26-Sep-12 4:58am.
|
|
|
|
|
The problem is that breadth-first search (bfs) tries ALL sequences of length N before it tries any of length N+1. And it stores all these intermediate attempts, resulting in your stack overflow for a deep solution.
An approach more specific to the problem would give better results, e.g.
for (int tile = 0; tile <= 8; ++tile)
placeTileInCorrectPosition (tile, board);
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
im sorry but what should i do with this peace of code , i didnt get it . can you explain more ?
this is iteration that go 8 time throw the board and place the tile in correct position i didnt get it honestly .
|
|
|
|
|
The function will generate the sequence of moves to place tile n in the correct position without disturbing the tiles < n, which have already been correctly placed.
This is more focused than blindly trying one solution after another, and will work faster and without a stack overflow.
Unfortunately writing this function takes a little more work than bfs. But it's doable.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
this is good soluation .
you mean with tile < n , that if i had a puzzle with this tiles
{{1,2,4}
{3,5,0}
{6,8,7})
its change the 4 with 3 and 8 with 7 and 0 with 8 , is that what you meaning .
and can you light me up with a source or website that has already done this thing . ty for ans my stupid qustion .
|
|
|
|
|
The function would generate the sequence of moves that would place 3 in the position 4 is in, while leaving 1 and 2 in their correct positions. This is because 3 is the next tile to be placed in its correct position.
I don't have source code, but it would be a good exercise for you to write it. Googling "9 puzzle solution" gets lots of hits, and one of them probably has some source code. Similar results can be obtained searching for "15 puzzle solution", which is another common form of this puzzle type.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
recording to your description about that method , it'll change the place of 4 and 3 with eatch other and dosnt touch the second tile bcz it is in its correct place . i have made sth . may you take alook on it . is that what you mean ?
[[^]]
but i think it cant find the soluation(path) bcz it should change the first and second tile .
i have read sth about manhaten distance , can i use this method in bfs sloving ?
it tell me all the steps that a puzzle needed for sorting , like this one
{{4,5,6}
,{3,1,8}
,{2,7,0}}
it needed 2+3+3+1+1+1+1+2 = it neede 14 steps for sorting it
A B
{{4,5,6} {{4,5,6}
,{3,1,8} ,{3,1,0}
,{2,0,7}} ,{2,7,8}}
A:1+2+3+3+1+1+1+1+1 = 14
B:2+3+3+1+1+1+1+1+1 = 14
, but it dosnt mean that we can sort the puzzle in 14 steps is just
give me the coast or sth like this , i think this algorithm help me in finding the path faster (im just worry about the stack overflow and the memory), but i didnt test it yet.
i have read sth about bfs that it says the bfs searhing (require exponential memory). what does that mean ? is that mean i should declear or define a plceholder or a sth like a memory for it to contain i dont know the nodes or the calculating instead of the memory . or sth like this , does that things i have said is right or i just made them by my self ?
modified 27-Sep-12 8:45am.
|
|
|
|
|
I am wondering if anyone knows of a more efficient algorithm to perform a bit-interleave/deinterleave that takes 256-bits and interleaves every 64-th bit in the output. For example, I want:
output = (bit[ 0] << 255) | (bit[ 64] << 254) | (bit[128] << 253) | (bit[192] << 252)
| (bit[ 1] << 251) | (bit[ 65] << 250) | (bit[129] << 249) | (bit[193] << 248)
| ...
| (bit[63] << 3) | (bit[127] << 2) | (bit[191] << 1) | (bit[255]) So far, I have the following algorithms (presented in untested C++):
__uint16 *data = new __uint16[32 / sizeof(__uint16)]; __uint64 *result = new __uint64[32 / sizeof(__uint64)]();
for (int resIdx = 0; resIdx < 4; ++resIdx) {
for (int dataIdx = resIdx; dataIdx < 16; dataIdx += 4) {
__uint64 temp = data[dataIdx];
temp |= temp << 24;
temp |= temp << 12;
temp &= 0x000F000F000F000FULL;
temp |= temp << 6;
temp |= temp << 3;
temp &= 0x1111111111111111ULL;
result[resIdx] |= temp << (dataIdx & 3);
}
}
__uint64 *data = new __uint64[32 / sizeof(__uint64)]; __uint16 *result = new __uint16[32 / sizeof(__uint16)];
for (int dataIdx = 0; dataIdx < 4; ++dataIdx) {
for (int resIdx = dataIdx; resIdx < 16; resIdx += 4) {
__uint64 temp = data[dataIdx] >> (resIdx >> 2);
temp &= 0x1111111111111111ULL;
temp |= temp >> 3;
temp |= temp >> 6;
temp &= 0x000F000F000F000FULL;
temp |= temp >> 12;
temp |= temp >> 24;
result[resIdx] = (__uint16)temp;
}
}
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
|
|
My problem goes something like this. I have a variable of 5 arrays a[5] for storing the 5nodes of a network. The network is randomly formed by the random number generator. I have the time of travel for each paths of the network. All the nodes may not be connected to eachother. The network and the time of travel of each path is as per the user has assigned. Now I have to check the elements of each array and assign the penalty as per the conditions. My main task is to find a network path traveling each node of the network only once such that the node visited is not repeated. Its similar to TSP but the difference is that in TSP has the condition that it is possible to travel from each node to every other node. But for my case the network is pre defined and nodes are not connected to every other nodes in the network.
a) Like if the network stored is 2-2-3-4-5 then I find that a[1]=a[2] so I will have to assign the penalty (type 1 )as the network has a path 2-2 which is not possible as the starting and end of the path is same. At the same time for rest of the paths from node 2 to 3, node 3 to 4, node 4 to 5 I will have to calculate the sum of total time of travel when I finally reach the node 5.
b) Also there is another penalty condition if the path is not a possible path in the network given by user then I will have to assign penaly( type 2) for such kind of condition like if 1-2-4-3-5 is a network to be checked. Here I am supposing that all the paths are possible but the path 4-3 doesn’t exist in the real network provided by the user, So for such cases I will have to calculate the sum of the time of travel for the paths which are possible and also assign the penalty (type 2)
c) There is also a condition that I need the end point of the network as node 5.So in the network generated randomly if the end node is not the node 5 then I will have to assign the penalty (type 3) and at the same time calculated the sum of the rest possible paths. For example the node 3-5-2-1-4 here the end node is 4 so I will have to assign the penalty(type 4)
d) Since I am not allowed to visit the same node twice I will have to assign the (penalty type 4) if the network has repeatition of nodes like if the network is 2-4-3-1-4. Here the node 4 is occurring twice so I will have to assign the penalty(type 4) and also calculate the sum of the time of travel of the other paths.
Considering all the above penalty conditions I will have to check the network s. I am really not being able to use any logic on how do I start. Need some hint on how do I do it.
|
|
|
|
|
Sorry, I see nothing difficult in this problem statement. Or maybe is it just that you never wrote a program ? Or are you asking how to represent the network topology and path costs ?
For a), scan the array and check if two consecutive indexes are the same.
For b), scan the array and check if every pair of indexes are linked in the user-supplied topology (you need some function that will query the topology and tell you if a link exists).
For c), the condition is a[5] != 5.
For d), use a double loop: the outer loop from i=1 to 4, the inner loop for j=i+1 to 5. In the body of the inner loop, test a[i] == a[j].
Accumulating the path costs is also obvious once you have a query function per network link.
|
|
|
|
|
Note: I see an interesting "resonance" between this question, and Roger Wright's question below: "A Modelling Question;" which I had not read before I made notes today about this "problem space," to post later on CP, when I got home !
For some reason today, while riding the elevators in a shopping mall that has three sets of two public-use elevators: in one end of the mall; in the other end of the mall; and in the middle of the mall ...
The idea came to me that it would be an interesting programming challenge (of a type I had never taken on before) to create an elevator use optimization solution: note that I have never studied differential equations, and I am not familiar with queue optimzation algorithms, etc.
Here's how I framed the problem:
1. Given #n sets of elevators, where the number in each set can vary from #1 to #n:
a. defining "set" to mean elevators that are adjacent, and that any button press on a floor that requests an elevator to go up, or down: simultaneously shares that request with every other elevator in its set that is not in use currently: i.e., stopped at one floor with the door closed, and no requests pending (that might be an unrealistic constraint ?).
2. Assuming all elevators serve the same the number of floors:
3. Assuming that the following time-stamped data, tagged with a unique ID for each elevator, is generated and sent to a central computer:
a. for every elevator the time it starts moving, and what floor it starts moving from.
b. for every elevator the time it stops moving, after being in motion, and the floor it stops on.
c. on every floor of the building, when someone presses an elevator up, or down, button (from outside the elevator) to request service:
d. data tagged by unique elevator ID containing the time of request-service button press, and the requested direction, up, or down.
e. inside the elevator: when any floor choice button is pressed: data tagged by unique elevator ID containing the time of floor-choice button press, and the destination floor chosen. So any one moment in time you have a complete list of all floors to be stopped-at by elevator #n.
3. when any elevator starts or stops moving is recorded tagged and time-stamped as in the above.
So, imagining we have all this incoming time-stamped information, and that some, or all, elevators are in use, some moving up, or down, some stopped.
The problem to be solved:
1. given a new request for service, up, or down, on floor #n of elevator #n:
2. and, given the context of pending requests and states of every other elevator in the set of which elevator #n is contained:
The desired result: to dispatch the elevators most efficiently, so they serve the most number of people in the smallest amount of time.
I'm not looking for "answers" by asking the question here: I am just looking for a few "pointers" to direct my initial study of the type of scheduling optimization this particular example represents.
Frankly, I don't have a clue about how to approach this kind of problem right now (no formal computer science courses for me, unfortunately).
Obviously could make this example much more complex by taking into real-world factors like most requests may originate from the ground-floor before based on some pattern (like, in a hotel: most request originate from the ground and/or check-in floor up to and a certain amount of time past, check-in time).
You could consider recording the exact times of elevator #n's door opening and closing, and figure out that if it's a short enough interval that no-one could have gotten on or off, so someone hit the close-door button immediately for whatever reason.
But all that type of complexity I don't want to even consider until I reach some understanding of basic optimization problems.
thanks, Bill
p.s. A difference I think I see between Roger Wright's simulation problem (if I can even begin to interpret it correctly), and the one I've described here is:
There are "unknowns" (see Roger's response here describing his inability to monitor pump-states in real-time):[^]) in Roger's complex system of pumps, wells, and flows; while, in the problem described here, there are no similar "unknowns:"
For every elevator #n: its current position; whether it is idle stopped on one floor; or moving up or down to some other floor; and, the number of floors it must stop at before reaching the top or bottom floor depending on which way its moving: is known precisely.
<color>"When it comes to atoms, language can be used only as in poetry. The poet, too, is not nearly so concerned with describing facts as with creating images." Niels Bohr
|
|
|
|
|