I am curious on how you came up with this data to disprove the
algorithm, is it just trial and error? I find myself in positions
where I can neither prove nor disprove my algorithm!
Not really trial and error. I have done my fair share of complex sorting so
I knew you cant solve all the cases with sorting either one way or the other.
Then it was just a case of demonstrating it with a few machines and
components and moving the parameters around till they didn't fit either
sorting. The problem is that you can't properly sort an object containing
two unrelated but equally importent properties. In my sample I sorted first
by one parameter and then by the other so
I ended up with a list looking like
10 10
10 20
20 10
20 20
30 01
You could argue that the last item should be higher up on the list. It
would be interesting to see if there is a simple solution to this problem,
but I'm afraid I don't know of one.
As a tip for debugging, use the DebuggerDisplay attribute to get faster
feedback in Visual Studio. A list of objects could den display useful
information instead of the type name of the object.
[DebuggerDisplay("Id = {ID}, Number of items {SomeList.Count}")]
class MyClass
{
public int ID
private List<string_someList = new List<string>();
public List<stringSomeList
{
get{ return _someList; }
}
}
A displaying a list of MyObject in debug mode would then show something like
1: "Id = 123, Number of items 2"
2: "Id = 124, Number of items 0"
3: "Id = 125, Number of items 1"
I added an Assigned property to my objects so after running the code sample
I could then just hover the machine or component list and immediatly see if
all components had a machine assigned.
--
Happy Coding!
Morten Wennevik [C# MVP]