

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, slapdowns and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Cofounder
Microsoft C++ MVP





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 "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
 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 into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
 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 Cofounder
Microsoft C++ MVP







Thank you.
Yes It is 3D Bin Packing, too.
But here:
1) We have several shelves.
2) If a place for an object was assigned, we can't put any objects on it, in front of it or in back.(just left side or right side is true)





Then you need to go and read some of the information in those links that Google provided.





funny!
what is wrong with you?
simply you can don't answer to me






That's a nice way of saying "thank you".
If there was an answer readily available, we would not have to write so much code. If you can do the procedure for one shelf, you can do it for multiple shelves.
So, where is the problem?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]





Try to write it as an integer linear programming model, it can be solved directly (maybe not efficiently, it depends) and it helps other people understand exactly what your problem looks like so we're sure we're all talking about the same problem.
If you have that, I'll gladly take a look at it.





This is not a 3D packing problem !
If you want to optimize the warehouse usage, you need to choose if you want to minimize wasted space or wasted weight.
an algo:
sort the cubes from biggest to smallest.
for each cube
Select available places
place the cube at the place which waste minimum
next
if your problem allow to put more than 1 cube in a place which is not stated), then it is 3D packing
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Thank you very much
This is my answer





Finally I did it:
public static string placeItemInBin(Item itemToPlacing)
{
LinkedListNode<Bin> binNode;
bool isPlaced = false;
int allSideStates = 1;
while (allSideStates <= 2)
{
binNode = listOfBins.First;
while (isPlaced == false && binNode != null)
{
if (binNode.Value.RemainWidth >= itemToPlacing.Width)
if (binNode.Value.RemainWeight >= itemToPlacing.Weight
&& binNode.Value.Height >= itemToPlacing.Height
&& binNode.Value.Depth >= itemToPlacing.Depth)
{
LinkedListNode<Partirion> partitionNode;
LinkedListNode<Partirion> Best;
Best=null;
partitionNode = binNode.Value.parts.First;
while (partitionNode != null)
{
if (partitionNode.Value.num == 1
&& partitionNode.Value.size >= itemToPlacing.Width
&& (Best == null  partitionNode.Value.size <= Best.Value.size))
{
Best = partitionNode;
if (Best.Value.size == itemToPlacing.Width)
break;
}
partitionNode = partitionNode.Next;
}
if (Best != null)
{
Partirion newPart = new Partirion(itemToPlacing.Width, itemToPlacing.Number,
Best.Value.cmBegin);
Best.Value.cmBegin += itemToPlacing.Width;
Best.Value.size = itemToPlacing.Width;
binNode.Value.parts.AddBefore(Best, newPart);
itemToPlacing.BinNumber = binNode.Value.Number;
binNode.Value.RemainWidth = itemToPlacing.Width;
binNode.Value.RemainWeight = itemToPlacing.Weight;
binNode.Value.RemainVolume = itemToPlacing.Width
* binNode.Value.Height * binNode.Value.Depth;
isPlaced = true;
return ("item: (" + itemToPlacing + ") ====> Bin: (" + binNode.Value + ")");
}
}
binNode = binNode.Next;
}
itemToPlacing.changeSideState();
allSideStates++;
}
return "Not Found";
}
modified 4 days ago.





Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Now you investigate to see what gives the best solution
 no sort of cubes
 sort from biggest to smallest
 sort from smallest to biggest
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Thanks
Yes; Best way is here:
LinkBinsOrItems.sortItemList(); LinkBinsOrItems.sortBinList();
Best Sort Mode:
private void btnBestMode_Click(object sender, EventArgs e)
{
if (LinkBinsOrItems.listOfBins == null)
{
if (LinkBinsOrItems.listOfItems == null) {
MessageBox.Show("Item List And Also Bin List Are Empty!!"
+"You Must Enter Bins And Items..."
, "Bin List And Item list Empty Error", MessageBoxButtons.OK
, MessageBoxIcon.Information);
return;
}
MessageBox.Show("Bin List Is Empty!! You Must Enter Bins...", "Bin List Empty Error"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (LinkBinsOrItems.listOfItems == null)
{
MessageBox.Show("Item List is Empty!! You Must Enter Items..."
, "Item List Empty Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
DialogResult result = MessageBox.Show("Are you sure you want to do sorting "
+"for creat more free space?(This can change items places"
, "Sort For Best Mode",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (result == DialogResult.No)
return;
LinkedListNode<Item> itemNode;
LinkedListNode<Bin> binNode;
itemNode = LinkBinsOrItems.listOfItems.First;
for (int i = 1; i <= LinkBinsOrItems.listOfItems.Count; i++)
{
itemNode.Value.BinNumber = 1;
}
binNode = LinkBinsOrItems.listOfBins.First;
for (int i = 1; i <= LinkBinsOrItems.listOfBins.Count; i++)
{
binNode.Value.clearRelations();
}
LinkBinsOrItems.sortItemList(); LinkBinsOrItems.sortBinList();
listBox1.Items.Add("");
itemNode = LinkBinsOrItems.listOfItems.First;
for (int i = 1; i <= LinkBinsOrItems.listOfItems.Count; i++)
{
listBox1.Items.Add(itemNode.Value);
listBox2.Items.Add(LinkBinsOrItems.placeItemInBin(itemNode.Value));
itemNode = itemNode.Next;
}
itemReportInitaling(); BinReportInitaling(); }





Cenator wrote: Thanks [Rose] Thank you.
CP have a standard way to reward contributors: click on the green arrow on left of the useful answer/advice. the author is rewarded with reputation points and you also gain some organizer points.

Depending on reality of the problem size of the warehouse and number of cubes to fit, you may want to optimize the answer even further.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





I wasn't sure if this forum was the best one for this question, so I apologize in advance if it isn't.
I'm currently learned Gene Expression Programming and I'm a little unclear as to how the mutation rate is applied to a population. I've looked at source code from different implementations and I've seen it used different ways and would like to know if there is actually a proper way to implement it or if it can be implement at the programmers discretion.
As an example, say there are 10 chromosomes, each with 2 genes, and each gene has 10 nodes and the mutation rate (mr) is 0.1. I've seen code that mutates nodes implemented in these way:
 Loop through each chromosome and generate a random number (rn) between 0  1 on each loop. If the rn <= mr then select the gene for mutation. Then loop through every node of the chromosome, ignoring gene boundaries (so in this example there are 20 nodes = 10 nodes/gene * 2 genes) and generate another rn and if the rn <= mr, mutate the node.
 Loop through each chromosome and generate a random number (rn) between 0  1 on each loop. If the rn <= mr then select the gene for mutation. Then loop through each gene, again generating a rn on each loop, and if the rn <= mr select the gene for mutation, otherwise continue the loop. If the gene is selected for mutation, loop through each node of the selected gene (10 nodes since there are 10 nodes/gene), generating a rn on each loop and mutate the selected node if rn <= mr.
 Randomly select 10% of the nodes in the entire populate (in this case 20 nodes since there are 200 nodes = 10 chromosomes * 2 genes/chromosome * 10 nodes/gene).
 Randomly select 10% of the chromosomes (in this case 1 chromosome) and then select the nodes for mutation following the same procedure as Item 1 or Item 2 above, starting from the second loop.
I believe that either Item 1 or Item 2 would be the correct way to apply the mutation operator, but I haven't been able to find a definitive answer either through searches on Google/CP or in the book I have been reading.
One other thing that is mentioned in the book I am reading, but isn't explained in detail is the following: there is a population of 10 chromosomes, each with 1 gene, and a total length of 14 nodes. The book states that the mutation rate should be equivalent to two onepoint mutations per chromosome, which in this case (because the chromosome's length is 14) should be 0.143. How was a mr of 0.143 derived from the chromosome length of 14? This isn't explained anywhere so far, even though this equivalence has been mentioned multiple times.
Any information, or links to answers, would be greatly appreciated. Thank you in advance for any help.
A black hole is where God tried to divide by zero.
There are 10 kinds of people in the world; those who understand binary and those who don't.





Hi all,
I have three arrays: X[i], Y[i] and Value[i], which are the position (x, y) of the pixel "i" and its value (pixel actived as 1, otherwise 0). Pleae have a look at this graph linked:
[See here, please: "graph"]
Data format is also shown at the right side of the graph. I would like to extract the subarray which represents connectedcomponents (or spots) in the image since the data is sorted in order of ascending x rather than in order of spots.
It is easy to achieve my purpose by programing in Matlab which already has some advance functions. But for the reason that it is huge data and low processing speed in matlab), I have to do carry out it by using C/C++.
Does anyone have some good idea to extract subarray for each spot? Thanks in advanced.
With best regards
feifeihanyu
modified 10Jul15 10:31am.





You need some extra information to connect the pixels that make a spot. As it stands there is no way to be certain that, for example, spot(5, 8) connects to the other two. What would happen if the blue spot was touching the red one, how would you tell where the separation occurs?





Hi, thanks for reply!
All connectedpixels make a spot! If the blue spot touchs the red one, then they are actually one spot!
There is an algorithm to label connectedcomponents in binary image. see here Blob detection
The difference from that example is that I already have arrays representing nonzero pixel positions with pixel values instead of a full binary image! The problem is that (x, y) of spots/blobs is sorted in order. so the positions (x, y) of different spots and blobs may mix together if they local at the same raw or column! for example, the positions of the red and the purple,please see my graph and right side, I labeled the positions from the same spot by lines.
Actually, I can transform the arrays into a full binary image, then perform a similar algorithm like Blob detection . But it will be a problem if I have many images which have few blobs but with big dimension, for example, 4096x4096. then it not wise to do that becasue many time will be wasted in loop search. I need an algorithm dealing with the arrays directly in stead of a full binary image. This is why I post a question here for asking for help.
regards
feifeihanyu
modified 10Jul15 12:21pm.





can somebody tell me who i can talk to regarding Mathematics and Algorithms





Member 11849553 wrote: who i can talk to regarding Mathematics and Algorithms You can talk to anybody about it. However, if you have a proper question, then feel free to post it in the appropriate forum.





If u take a tour of MATLAB groups you`ll most probably find some'C' export tool that converts your mfiles to cfiles. whether or not the generated code has the optimum performance is source of discussion.
for this special example, you might also look 4 3rd party graphic processing/rendering libraries(boost::gli,Qt,mapserver,gdal...).





on second thought, you can set up an output hash table that collects all connected points under the same hash. then use the floodfill algorithm to paint the spots; ie. gather points under hash values in the table and remove painted points from input container. this way beginning of the input container always contains the next first unpainted point.





My maths is quite poor and I need some help writing an algorithm/pseudo for a simple cost estimator:
rules
I have three inputs x, y and z. The inputs each have a separate max value that if breached return an error. These max values, X = 20, Y = 15, Z = 30.
Now I need a function that compares the inputted values and if possible swaps the values to keep them under the constraints. Also,
Z should always contain the smallest value as long as the swapped value still meets the max value constraints.
So for a few examples if the user entered X=15,Y=5,Z=10 the values for y and Z would be swapped to make z the lowest value. With X=5 Y=18 Z=2 X and Y would be swapped with x to fit under max values. With X=10 Y=8 Z=2 nothing would be swapped. X=31 Y=18 Z=10 nothing would be swapped and you would get an error.
I have written this codepen so far:
http://codepen.io/FredHair/pen/gpvoPR?editors=101[^]
It finds the minVal, medVal and maxVal. I just need some help with the next logic steps for swapping the values.
The values themself represent a bounding box, orientating an inputted box that would lead to a cost estimate.
I have already had a go at writing this into a program but I made numerous logical errors.
If anyone can offer any insight into the maths and best way to write this I can then write the code.
Any help is greatly appriceted, I hope I have made myslef clear, feel free to look at codepen and ask any questions.
Regards,
F





Here's a piece of the solution:
<pre lang="c#"> void SwapValues (ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
Now you have to write the "if" statements to determine the calls to SwapValues to get your variables in numeric order.





This code sort X, Y and Z so that X > Y > Z
code between 'then' and 'endif' is swaping values
if x < y then t= x; x= y; y= t; endif
if x < z then t= x; x= z; z= t; endif
if y < z then t= y; y= z; z= t; endif
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Hi All
I had to solve a specific problem for a client, this problem take some time to come with a original solution, that is working.
What i would like to know is if my solution is a original solution, if it fits as an algorithm or more like a recipe (since is very specific to this problem), and also if it is an original algorithm where should I publish it.
Thanks in avance for your answers.
Now the problem:
I Work with business process management, a common issue in BPM is who to define who does which tasks and how to implement a rule based on the responsabilities and role of the user.
In this case an aproval depend on the CEO (the one that must do the task). However he can delegate the task (everytime or in vacation) to the CFO and Manager A.
Also the Manager A delegates to both the Assistant Manager 1 (AM1) and Assistant Manager 2 (AM2), and the CFO delegates to Finantial Manager A (FMA) and Finantial Manager B (FMB).
So a process may be aproved by any of these groups:
 CEO
 CFO and Manager A
 CFO and AM1 and AM2
 FMA and AM1 and AM2
 FMB and AM1 and AM2
 FMA and Manager A
 FMB and Manager B
Second part:
(Assume CEO  Level 1, CFO  Level 2, Manager A  Level 2, The others  Level 3)
We seen that someone in level 2 can aprove with someone in level 3 of another branch.
However it gets tricky since AM1 (level 3) can delegate its on tasks on CFO (level 2 of the other branch)
So this line
 CFO and AM1 and AM2
turns into 2 lines:
 CFO and AM1 and AM2
 CFO and CFO and AM2 (because CFO only aproves once so it become:  CFO and AM2)
This seems hard, but belive i am not give all the requirements, the real problem as some issues more, but the main question is the one I explained above.
The Solution
I will give the solution, maybe write an article where. However first i want to know if it already exists, or something similar. But google for task delegation returns results obviously nothing to do with this problem.





Hi,
Seems related to oriented graph
Numerous mathematical tools exist for graphs.
So there is little chance that your solution is original, or at least efficient tools already exist for this family of problems.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Tanks ppolymorphe
I was always looking at trees and not graphs.
After your tip i did some research and i think my solution fits more or less in Direct Acyclic Graph more than oriented graph. The image (of the Hasse diagram) in this site is prety similiar with my solution https://en.wikipedia.org/wiki/Directed_acyclic_graph[^]
I am going to read some more about this.





Rui__Silva wrote: Tanks ppolymorphe You're welcome.
Rui__Silva wrote: After your tip i did some research and i think my solution fits more or less in Direct Acyclic Graph more than oriented graph. Oriented is a direct translation from French, the right translation is Directed
Glad you found what you were looking for.
 If you consider my answer useful, you can up vote it (green arrow when the mouse is on left at beginning of answer).
 If you think the problem solved, change the tittle of your question and add Answered or Solved
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Anonymous downvote countered.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
 Homer





Thanks you ! Thanks you ! Thanks you all up voters
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
modified 1Jul15 14:36pm.





Hello, everybody.
I've got next problem. There is three objects:
1. first one, with next characteristics: circular area of view, speed, drag coefficient;
2. wind (or water current, doesn't matter; some sort of resistance) with some strength and direction;
3. polygon, concave (in general case).
I need to build path of first object inside this polygon, which will:
1. cover whole polygon by view area;
2. be optimal by travel time;
3. takes into account wind direction and strength.
In other words, I need to carry out exploration in a given area on optimal trajectory while scout can be drift away.
Thanks, Viktor.





Do you have a question?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson





My question, actually, is: what algorithms should I use to build this trajectory?.. I know, that maybe this is strange. I investigate this problem last few days and already have some sort of solution. I just want to find some people who might solve this task earlier.





Viktor Grabarchuk wrote: I just want to find some people who might solve this task earlier. The thing has a location, a direction (vector, some arrow) and a speed (velocity in them expensive manuals)
Once you have those three things in an oject, you can introduce "forces" like gravity.
Do keep in mind that you are asking for something rather complex; there is a huge difference in resistance between wind and water, also depending on the shape of the object it hits, any currents that form due to that shape, any contaminations and other stuff. Other stuff like temperatures of below 0 where water does not tend to flow
Start out with something fun one can easily play with; have a ball bounce on the screen and change the gravity to be equal to the moon. Once you have one force, introducing a new one should not be hard.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]





I have a an array of values like:
array(0.2,0.0,0.4,0.7) min: 0.0 , max: 5.0
and every value represent something and I have some attributes in the database that corresponds to these values. Now what I need to do is I need to search the records from database on the bases of above mentioned array. Kindly suggest me an algorithm that would do something like this. I need something like machine learning that would be able to do this thing with flexibility. What I have found from my research that following algorithm is closer to what I am looking for:
http://www.econ.ohiostate.edu/jpeck/Econ501aL4.pdf
http://www.solver.com/knearestneighborsclassificationexample
For Example: Configuration array => ('attr1'=> 0.2, 'attr2'=>0.54, 'attr3'=>0.66, 'attr4'=> 0.78)
Records:
 attr1  attr2  attr3  attr4 
1) 0.45 0.33 0.55 0.66
2) 0.32 0.12 0.34 0.99
3) 0.78 0.41 0.10 0.74
4) 0.88 0.12 0.74 0.10
5) 0.72 0.02 0.00 0.55
Now I need an algorithm which can get me results (records) using the above mentioned array.






I have a quick question.
Which type of math subjects should i refresh myself on for algorithms class??
Is there any Direct recources i can find for this??
Thankyou






There's no specific math subject that would be more important than others for algorithms in general. The most important skill for developing or understanding algorithms is logical thinking and the ability to break a problem into smaller parts. Unless, of course, if you're going to deal with algorithms for a specific problem domain in particular  like graphics or sound processing  then certain math subjects will certainly be more helpful than others.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson





Not just for algorithms, but for Computer Science in an overall sense  Mathematics for Computer Science[^]. You'll also find video lectures there.
modified 5Jun15 1:48am.





I would say Boole Algebra.
Everywhere you have a condition, it is Boole Algebra.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Hi friends,
find the θ bound for f(n)=n2/2n/2?
we need to find the upper bound and lower bound.
If anybody know please send the solution with explaination.
Thanks,
Arjun





C
modified 23May15 13:46pm.





Chaitanya Pai wrote: I have tried a lot to arrive at the solution. Show what you have tried and explain what does not work, and people will try to help you. But no one is going to hand you a complete solution.
modified 23May15 8:16am.





I am having a major 'head against wall' problem here...
Given two base 36 values ('A0ZWS0P' and 'A0ZWS9P', for example) and a third (random) value,
how would you go about determining whether the random value was 'between' the starting and ending values?
I am working in 2012 VB.Net





It depends on how you're (internally) representing the values.
If you're using regular .NET integer types (e.g., Int32, Int64) then just compare the values.
If you're using strings to represent the values, then
1. if necessary, pad the strings to the same length (leading spaces or zeros)
2. use a caseINsensitive string comparison.
The string representation is a very poor design for something like this!
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.



