Whose Fish - OO solution

This is a discussion on Whose Fish - OO solution within the Theory and Concepts forums in category; Jordan Marr wrote: > On Jun 17, 8:48 pm, Kreeg <k...{}sentdotcom.nospam> wrote: >> Jordan Marr wrote: >>> I never posted my solution to Whose Fish, and since my old thread >>> probably has a stigma attached to it, I'll post it here. >> *SNIP the rest of Jordan's code* >> >> I had commented earlier that I'd like to see a linq implementation of >> this problem. Well, in an attempt to salvage this thread at least a >> little bit, I thought I'd give one a try. >> >> I used Jordan's OO implementation as a base, and basically ...

Go Back   Application Development Forum > Theory and Concepts

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #61  
Old 06-18-2007, 03:04 PM
Kreeg
Guest
 
Default Re: Whose Fish - OO solution



Jordan Marr wrote:
> On Jun 17, 8:48 pm, Kreeg <k...{}sentdotcom.nospam> wrote:
>> Jordan Marr wrote:
>>> I never posted my solution to Whose Fish, and since my old thread
>>> probably has a stigma attached to it, I'll post it here.

>> *SNIP the rest of Jordan's code*
>>
>> I had commented earlier that I'd like to see a linq implementation of
>> this problem. Well, in an attempt to salvage this thread at least a
>> little bit, I thought I'd give one a try.
>>
>> I used Jordan's OO implementation as a base, and basically used his
>> entity objects without modification (I did end up adding a constructor
>> to the Street class).
>>
>> Jordan's code that I stole so much from can be found here:
>>
>> http://groups.google.com/group/comp....c3044ff3069baa
>>
>> I cheated a bit (well, maybe a lot) and just used his IsValid rules to
>> do my filtering, and used linq to make some other parts of the code a
>> little clearer and more compact, I think. I actually end up liking the
>> finished product a fair bit. Maybe I'll try to make it all linq in the
>> future, but here's what I have. It's the first Linq that I've done, so
>> I may well have missed some obvious things.
>>
>> On my laptop (a lowly centrino 1.4ghz) this runs in about 3 seconds.
>>
>> using System;
>> using System.Collections.Generic;
>> using System.Linq;
>> using System.Text;
>> using BusinessFramework;
>> using Entities;
>>
>> namespace Whose_Fish
>> {
>> class LinqProgram
>> {
>> public void Solve()
>> {
>> //no cross join in linq AFAIK, so I have to do an inner
>> join on 1 == 1
>> var allHouses = from Nationalities n in
>> Enum.GetValues(typeof(Nationalities))
>> join HouseColors c in
>> Enum.GetValues(typeof(HouseColors)) on 1 equals 1
>> join Drinks d in
>> Enum.GetValues(typeof(Drinks)) on 1 equals 1
>> join Pets p in
>> Enum.GetValues(typeof(Pets)) on 1 equals 1
>> join Smokes s in
>> Enum.GetValues(typeof(Smokes)) on 1 equals 1
>> join int o in new int[]{0,1,2,3,4} on 1
>> equals 1
>> select new House() { Nationality = n,
>> HouseColor = c, Drink = d, Order=o, Pet=p, Smoke=s };
>>
>> var validHouses = from h in allHouses
>> where h.IsValid
>> select h;
>>
>> Console.WriteLine("{0} valid houses", validHouses.Count());
>>
>> var streets = from h1 in validHouses
>> where h1.Order == 0
>> join h2 in validHouses on 1 equals h2.Order
>> join h3 in validHouses on 2 equals h3.Order
>> join h4 in validHouses on 3 equals h4.Order
>> join h5 in validHouses on 4 equals h5.Order
>> select new Street(h1, h2, h3, h4, h5);
>>
>> Console.WriteLine("{0} total street permutations.",
>> streets.Count());
>>
>> var result = from s in streets
>> where s.IsValid
>> select s;
>>
>> foreach (Street h in result)
>> {
>> Console.WriteLine(h.DescribeStreet());
>> }
>>
>> Console.ReadKey();
>> }
>> }
>>
>>
>>
>> }
>>
>>> Jordan- Hide quoted text -

>> - Show quoted text -

>
> 3 seconds... that is even faster than the SQL example. Linq seems to
> have provided the fastest solution yet!
>
> Does changing the order of the enum lists have any noticeable affect
> on the time?
>


I'll have to try that tonight. Just to clarify, are you talking about
changing the order of the values within the enums, or changing the order
in which the enums are joined together to form the list of House
permutations? I'm assuming the former.

I wouldn't think that it would have any effect, though, because unlike
your code mine iterates over all of the possible Street permutations no
matter what. If I remember correctly yours had a short-circuit where if
it found a valid street it stopped processing, right? Were your
performance differences because of that short circuit, where a correct
answer early in the list of Street permutations short-circuits the rest
of the list?

> Jordan
>

Reply With Quote
  #62  
Old 06-18-2007, 03:12 PM
Kreeg
Guest
 
Default Re: Whose Fish - OO solution



Jordan Marr wrote:
> On Jun 17, 8:48 pm, Kreeg <k...{}sentdotcom.nospam> wrote:
>> Jordan Marr wrote:
>>> I never posted my solution to Whose Fish, and since my old thread
>>> probably has a stigma attached to it, I'll post it here.

>> *SNIP the rest of Jordan's code*
>>
>> I had commented earlier that I'd like to see a linq implementation of
>> this problem. Well, in an attempt to salvage this thread at least a
>> little bit, I thought I'd give one a try.
>>
>> I used Jordan's OO implementation as a base, and basically used his
>> entity objects without modification (I did end up adding a constructor
>> to the Street class).
>>
>> Jordan's code that I stole so much from can be found here:
>>
>> http://groups.google.com/group/comp....c3044ff3069baa
>>
>> I cheated a bit (well, maybe a lot) and just used his IsValid rules to
>> do my filtering, and used linq to make some other parts of the code a
>> little clearer and more compact, I think. I actually end up liking the
>> finished product a fair bit. Maybe I'll try to make it all linq in the
>> future, but here's what I have. It's the first Linq that I've done, so
>> I may well have missed some obvious things.
>>
>> On my laptop (a lowly centrino 1.4ghz) this runs in about 3 seconds.
>>
>> using System;
>> using System.Collections.Generic;
>> using System.Linq;
>> using System.Text;
>> using BusinessFramework;
>> using Entities;
>>
>> namespace Whose_Fish
>> {
>> class LinqProgram
>> {
>> public void Solve()
>> {
>> //no cross join in linq AFAIK, so I have to do an inner
>> join on 1 == 1
>> var allHouses = from Nationalities n in
>> Enum.GetValues(typeof(Nationalities))
>> join HouseColors c in
>> Enum.GetValues(typeof(HouseColors)) on 1 equals 1
>> join Drinks d in
>> Enum.GetValues(typeof(Drinks)) on 1 equals 1
>> join Pets p in
>> Enum.GetValues(typeof(Pets)) on 1 equals 1
>> join Smokes s in
>> Enum.GetValues(typeof(Smokes)) on 1 equals 1
>> join int o in new int[]{0,1,2,3,4} on 1
>> equals 1
>> select new House() { Nationality = n,
>> HouseColor = c, Drink = d, Order=o, Pet=p, Smoke=s };
>>
>> var validHouses = from h in allHouses
>> where h.IsValid
>> select h;
>>
>> Console.WriteLine("{0} valid houses", validHouses.Count());
>>
>> var streets = from h1 in validHouses
>> where h1.Order == 0
>> join h2 in validHouses on 1 equals h2.Order
>> join h3 in validHouses on 2 equals h3.Order
>> join h4 in validHouses on 3 equals h4.Order
>> join h5 in validHouses on 4 equals h5.Order
>> select new Street(h1, h2, h3, h4, h5);
>>
>> Console.WriteLine("{0} total street permutations.",
>> streets.Count());
>>
>> var result = from s in streets
>> where s.IsValid
>> select s;
>>
>> foreach (Street h in result)
>> {
>> Console.WriteLine(h.DescribeStreet());
>> }
>>
>> Console.ReadKey();
>> }
>> }
>>
>>
>>
>> }
>>
>>> Jordan- Hide quoted text -

>> - Show quoted text -

>
> 3 seconds... that is even faster than the SQL example. Linq seems to
> have provided the fastest solution yet!
>
> Does changing the order of the enum lists have any noticeable affect
> on the time?
>


My apologies if this ends up double-posting. :-/

I'll have to try that tonight. Just to clarify, are you talking about
changing the order of the values within the enums, or changing the order
in which the enums are joined together to form the list of House
permutations? I'm assuming the former.

I wouldn't think that it would have any effect, though, because unlike
your code mine iterates over all of the possible Street permutations no
matter what. If I remember correctly yours had a short-circuit where if
it found a valid street it stopped processing, right? Were your
performance differences because of that short circuit, where a correct
answer early in the list of Street permutations short-circuits the rest
of the list?


> Jordan
>

Reply With Quote
  #63  
Old 06-18-2007, 11:32 PM
Kreeg
Guest
 
Default Re: Whose Fish - OO solution



Jordan Marr wrote:
> On Jun 17, 8:48 pm, Kreeg <k...{}sentdotcom.nospam> wrote:
>> Jordan Marr wrote:
>>> I never posted my solution to Whose Fish, and since my old thread
>>> probably has a stigma attached to it, I'll post it here.

>> *SNIP the rest of Jordan's code*
>>
>> I had commented earlier that I'd like to see a linq implementation of
>> this problem. Well, in an attempt to salvage this thread at least a
>> little bit, I thought I'd give one a try.
>>
>> I used Jordan's OO implementation as a base, and basically used his
>> entity objects without modification (I did end up adding a constructor
>> to the Street class).
>>
>> Jordan's code that I stole so much from can be found here:
>>
>> http://groups.google.com/group/comp....c3044ff3069baa
>>
>> I cheated a bit (well, maybe a lot) and just used his IsValid rules to
>> do my filtering, and used linq to make some other parts of the code a
>> little clearer and more compact, I think. I actually end up liking the
>> finished product a fair bit. Maybe I'll try to make it all linq in the
>> future, but here's what I have. It's the first Linq that I've done, so
>> I may well have missed some obvious things.
>>
>> On my laptop (a lowly centrino 1.4ghz) this runs in about 3 seconds.
>>
>> using System;
>> using System.Collections.Generic;
>> using System.Linq;
>> using System.Text;
>> using BusinessFramework;
>> using Entities;
>>
>> namespace Whose_Fish
>> {
>> class LinqProgram
>> {
>> public void Solve()
>> {
>> //no cross join in linq AFAIK, so I have to do an inner
>> join on 1 == 1
>> var allHouses = from Nationalities n in
>> Enum.GetValues(typeof(Nationalities))
>> join HouseColors c in
>> Enum.GetValues(typeof(HouseColors)) on 1 equals 1
>> join Drinks d in
>> Enum.GetValues(typeof(Drinks)) on 1 equals 1
>> join Pets p in
>> Enum.GetValues(typeof(Pets)) on 1 equals 1
>> join Smokes s in
>> Enum.GetValues(typeof(Smokes)) on 1 equals 1
>> join int o in new int[]{0,1,2,3,4} on 1
>> equals 1
>> select new House() { Nationality = n,
>> HouseColor = c, Drink = d, Order=o, Pet=p, Smoke=s };
>>
>> var validHouses = from h in allHouses
>> where h.IsValid
>> select h;
>>
>> Console.WriteLine("{0} valid houses", validHouses.Count());
>>
>> var streets = from h1 in validHouses
>> where h1.Order == 0
>> join h2 in validHouses on 1 equals h2.Order
>> join h3 in validHouses on 2 equals h3.Order
>> join h4 in validHouses on 3 equals h4.Order
>> join h5 in validHouses on 4 equals h5.Order
>> select new Street(h1, h2, h3, h4, h5);
>>
>> Console.WriteLine("{0} total street permutations.",
>> streets.Count());
>>
>> var result = from s in streets
>> where s.IsValid
>> select s;
>>
>> foreach (Street h in result)
>> {
>> Console.WriteLine(h.DescribeStreet());
>> }
>>
>> Console.ReadKey();
>> }
>> }
>>
>>
>>
>> }
>>
>>> Jordan- Hide quoted text -

>> - Show quoted text -

>
> 3 seconds... that is even faster than the SQL example. Linq seems to
> have provided the fastest solution yet!
>
> Does changing the order of the enum lists have any noticeable affect
> on the time?
>


My apologies if this ends up double-posting. :-/

I'll have to try that. Just to clarify, are you talking about changing
the order of the values within the enums, or changing the order in which
the enums are joined together to form the list of House permutations?
I'm assuming the former.

I wouldn't think that it would have any effect, though, because unlike
your code mine iterates over all of the possible Street permutations no
matter what. If I remember correctly yours had a short-circuit where if
it found a valid street it stopped processing, right? Were your
performance differences because of that short circuit, where a correct
answer early in the list of Street permutations short-circuits the rest
of the list?

> Jordan
>

Reply With Quote
  #64  
Old 06-20-2007, 12:43 PM
Jordan Marr
Guest
 
Default Re: Whose Fish - OO solution

On Jun 18, 3:04 pm, Kreeg <k...{}sentdotcom.nospam.com> wrote:
> Jordan Marr wrote:
> > On Jun 17, 8:48 pm, Kreeg <k...{}sentdotcom.nospam> wrote:
> >> Jordan Marr wrote:
> >>> I never posted my solution to Whose Fish, and since my old thread
> >>> probably has a stigma attached to it, I'll post it here.
> >> *SNIP the rest of Jordan's code*

>
> >> I had commented earlier that I'd like to see a linq implementation of
> >> this problem. Well, in an attempt to salvage this thread at least a
> >> little bit, I thought I'd give one a try.

>
> >> I used Jordan's OO implementation as a base, and basically used his
> >> entity objects without modification (I did end up adding a constructor
> >> to the Street class).

>
> >> Jordan's code that I stole so much from can be found here:

>
> >>http://groups.google.com/group/comp....c3044ff3069baa

>
> >> I cheated a bit (well, maybe a lot) and just used his IsValid rules to
> >> do my filtering, and used linq to make some other parts of the code a
> >> little clearer and more compact, I think. I actually end up liking the
> >> finished product a fair bit. Maybe I'll try to make it all linq in the
> >> future, but here's what I have. It's the first Linq that I've done, so
> >> I may well have missed some obvious things.

>
> >> On my laptop (a lowly centrino 1.4ghz) this runs in about 3 seconds.

>
> >> using System;
> >> using System.Collections.Generic;
> >> using System.Linq;
> >> using System.Text;
> >> using BusinessFramework;
> >> using Entities;

>
> >> namespace Whose_Fish
> >> {
> >> class LinqProgram
> >> {
> >> public void Solve()
> >> {
> >> //no cross join in linq AFAIK, so I have to do an inner
> >> join on 1 == 1
> >> var allHouses = from Nationalities n in
> >> Enum.GetValues(typeof(Nationalities))
> >> join HouseColors c in
> >> Enum.GetValues(typeof(HouseColors)) on 1 equals 1
> >> join Drinks d in
> >> Enum.GetValues(typeof(Drinks)) on 1 equals 1
> >> join Pets p in
> >> Enum.GetValues(typeof(Pets)) on 1 equals 1
> >> join Smokes s in
> >> Enum.GetValues(typeof(Smokes)) on 1 equals 1
> >> join int o in new int[]{0,1,2,3,4} on 1
> >> equals 1
> >> select new House() { Nationality = n,
> >> HouseColor = c, Drink = d, Order=o, Pet=p, Smoke=s };

>
> >> var validHouses = from h in allHouses
> >> where h.IsValid
> >> select h;

>
> >> Console.WriteLine("{0} valid houses", validHouses.Count());

>
> >> var streets = from h1 in validHouses
> >> where h1.Order == 0
> >> join h2 in validHouses on 1 equals h2.Order
> >> join h3 in validHouses on 2 equals h3.Order
> >> join h4 in validHouses on 3 equals h4.Order
> >> join h5 in validHouses on 4 equals h5.Order
> >> select new Street(h1, h2, h3, h4, h5);

>
> >> Console.WriteLine("{0} total street permutations.",
> >> streets.Count());

>
> >> var result = from s in streets
> >> where s.IsValid
> >> select s;

>
> >> foreach (Street h in result)
> >> {
> >> Console.WriteLine(h.DescribeStreet());
> >> }

>
> >> Console.ReadKey();
> >> }
> >> }

>
> >> }

>
> >>> Jordan- Hide quoted text -
> >> - Show quoted text -

>
> > 3 seconds... that is even faster than the SQL example. Linq seems to
> > have provided the fastest solution yet!

>
> > Does changing the order of the enum lists have any noticeable affect
> > on the time?

>
> I'll have to try that tonight. Just to clarify, are you talking about
> changing the order of the values within the enums, or changing the order
> in which the enums are joined together to form the list of House
> permutations? I'm assuming the former.
>
> I wouldn't think that it would have any effect, though, because unlike
> your code mine iterates over all of the possible Street permutations no
> matter what. If I remember correctly yours had a short-circuit where if
> it found a valid street it stopped processing, right? Were your
> performance differences because of that short circuit, where a correct
> answer early in the list of Street permutations short-circuits the rest
> of the list?
>
>
>
> > Jordan- Hide quoted text -

>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


That is correct. It iterates until it finds a valid street and then
stops.
So you're saying that the Linq solution iterates all streets (no short
circuit). If the same validation logic is taking place *more times*
in the Linq version, how does Linq make it run so much faster? It
still has to loop through and run the validation algorithm.

Thoughts?

Jordan

Reply With Quote
  #65  
Old 06-20-2007, 04:24 PM
Kreeg
Guest
 
Default Re: Whose Fish - OO solution



Jordan Marr wrote:
> On Jun 18, 3:04 pm, Kreeg <k...{}sentdotcom.nospam.com> wrote:
>> Jordan Marr wrote:
>>> On Jun 17, 8:48 pm, Kreeg <k...{}sentdotcom.nospam> wrote:
>>>> Jordan Marr wrote:
>>>>> I never posted my solution to Whose Fish, and since my old thread
>>>>> probably has a stigma attached to it, I'll post it here.
>>>> *SNIP the rest of Jordan's code*
>>>> I had commented earlier that I'd like to see a linq implementation of
>>>> this problem. Well, in an attempt to salvage this thread at least a
>>>> little bit, I thought I'd give one a try.
>>>> I used Jordan's OO implementation as a base, and basically used his
>>>> entity objects without modification (I did end up adding a constructor
>>>> to the Street class).
>>>> Jordan's code that I stole so much from can be found here:
>>>> http://groups.google.com/group/comp....c3044ff3069baa
>>>> I cheated a bit (well, maybe a lot) and just used his IsValid rules to
>>>> do my filtering, and used linq to make some other parts of the code a
>>>> little clearer and more compact, I think. I actually end up liking the
>>>> finished product a fair bit. Maybe I'll try to make it all linq in the
>>>> future, but here's what I have. It's the first Linq that I've done, so
>>>> I may well have missed some obvious things.
>>>> On my laptop (a lowly centrino 1.4ghz) this runs in about 3 seconds.
>>>> using System;
>>>> using System.Collections.Generic;
>>>> using System.Linq;
>>>> using System.Text;
>>>> using BusinessFramework;
>>>> using Entities;
>>>> namespace Whose_Fish
>>>> {
>>>> class LinqProgram
>>>> {
>>>> public void Solve()
>>>> {
>>>> //no cross join in linq AFAIK, so I have to do an inner
>>>> join on 1 == 1
>>>> var allHouses = from Nationalities n in
>>>> Enum.GetValues(typeof(Nationalities))
>>>> join HouseColors c in
>>>> Enum.GetValues(typeof(HouseColors)) on 1 equals 1
>>>> join Drinks d in
>>>> Enum.GetValues(typeof(Drinks)) on 1 equals 1
>>>> join Pets p in
>>>> Enum.GetValues(typeof(Pets)) on 1 equals 1
>>>> join Smokes s in
>>>> Enum.GetValues(typeof(Smokes)) on 1 equals 1
>>>> join int o in new int[]{0,1,2,3,4} on 1
>>>> equals 1
>>>> select new House() { Nationality = n,
>>>> HouseColor = c, Drink = d, Order=o, Pet=p, Smoke=s };
>>>> var validHouses = from h in allHouses
>>>> where h.IsValid
>>>> select h;
>>>> Console.WriteLine("{0} valid houses", validHouses.Count());
>>>> var streets = from h1 in validHouses
>>>> where h1.Order == 0
>>>> join h2 in validHouses on 1 equals h2.Order
>>>> join h3 in validHouses on 2 equals h3.Order
>>>> join h4 in validHouses on 3 equals h4.Order
>>>> join h5 in validHouses on 4 equals h5.Order
>>>> select new Street(h1, h2, h3, h4, h5);
>>>> Console.WriteLine("{0} total street permutations.",
>>>> streets.Count());
>>>> var result = from s in streets
>>>> where s.IsValid
>>>> select s;
>>>> foreach (Street h in result)
>>>> {
>>>> Console.WriteLine(h.DescribeStreet());
>>>> }
>>>> Console.ReadKey();
>>>> }
>>>> }
>>>> }
>>>>> Jordan- Hide quoted text -
>>>> - Show quoted text -
>>> 3 seconds... that is even faster than the SQL example. Linq seems to
>>> have provided the fastest solution yet!
>>> Does changing the order of the enum lists have any noticeable affect
>>> on the time?

>> I'll have to try that tonight. Just to clarify, are you talking about
>> changing the order of the values within the enums, or changing the order
>> in which the enums are joined together to form the list of House
>> permutations? I'm assuming the former.
>>
>> I wouldn't think that it would have any effect, though, because unlike
>> your code mine iterates over all of the possible Street permutations no
>> matter what. If I remember correctly yours had a short-circuit where if
>> it found a valid street it stopped processing, right? Were your
>> performance differences because of that short circuit, where a correct
>> answer early in the list of Street permutations short-circuits the rest
>> of the list?
>>
>>
>>
>>> Jordan- Hide quoted text -

>> - Show quoted text -- Hide quoted text -
>>
>> - Show quoted text -

>
> That is correct. It iterates until it finds a valid street and then
> stops.
> So you're saying that the Linq solution iterates all streets (no short
> circuit). If the same validation logic is taking place *more times*
> in the Linq version, how does Linq make it run so much faster? It
> still has to loop through and run the validation algorithm.
>
> Thoughts?
>


When you timed your solution, did you have the Console.Writeline in each
iteration? I had your implementation up and running on my machine
without outputting to the console, and it ran in about the same amount
of time as the Linq solution.

> Jordan
>

Reply With Quote
  #66  
Old 06-21-2007, 11:33 AM
Jordan Marr
Guest
 
Default Re: Whose Fish - OO solution

On Jun 20, 4:24 pm, Kreeg <k...{}sentdotcom.nospam> wrote:
> Jordan Marr wrote:
> > On Jun 18, 3:04 pm, Kreeg <k...{}sentdotcom.nospam.com> wrote:
> >> Jordan Marr wrote:
> >>> On Jun 17, 8:48 pm, Kreeg <k...{}sentdotcom.nospam> wrote:
> >>>> Jordan Marr wrote:
> >>>>> I never posted my solution to Whose Fish, and since my old thread
> >>>>> probably has a stigma attached to it, I'll post it here.
> >>>> *SNIP the rest of Jordan's code*
> >>>> I had commented earlier that I'd like to see a linq implementation of
> >>>> this problem. Well, in an attempt to salvage this thread at least a
> >>>> little bit, I thought I'd give one a try.
> >>>> I used Jordan's OO implementation as a base, and basically used his
> >>>> entity objects without modification (I did end up adding a constructor
> >>>> to the Street class).
> >>>> Jordan's code that I stole so much from can be found here:
> >>>>http://groups.google.com/group/comp....c3044ff3069baa
> >>>> I cheated a bit (well, maybe a lot) and just used his IsValid rules to
> >>>> do my filtering, and used linq to make some other parts of the code a
> >>>> little clearer and more compact, I think. I actually end up liking the
> >>>> finished product a fair bit. Maybe I'll try to make it all linq in the
> >>>> future, but here's what I have. It's the first Linq that I've done, so
> >>>> I may well have missed some obvious things.
> >>>> On my laptop (a lowly centrino 1.4ghz) this runs in about 3 seconds.
> >>>> using System;
> >>>> using System.Collections.Generic;
> >>>> using System.Linq;
> >>>> using System.Text;
> >>>> using BusinessFramework;
> >>>> using Entities;
> >>>> namespace Whose_Fish
> >>>> {
> >>>> class LinqProgram
> >>>> {
> >>>> public void Solve()
> >>>> {
> >>>> //no cross join in linq AFAIK, so I have to do an inner
> >>>> join on 1 == 1
> >>>> var allHouses = from Nationalities n in
> >>>> Enum.GetValues(typeof(Nationalities))
> >>>> join HouseColors c in
> >>>> Enum.GetValues(typeof(HouseColors)) on 1 equals 1
> >>>> join Drinks d in
> >>>> Enum.GetValues(typeof(Drinks)) on 1 equals 1
> >>>> join Pets p in
> >>>> Enum.GetValues(typeof(Pets)) on 1 equals 1
> >>>> join Smokes s in
> >>>> Enum.GetValues(typeof(Smokes)) on 1 equals 1
> >>>> join int o in new int[]{0,1,2,3,4} on 1
> >>>> equals 1
> >>>> select new House() { Nationality = n,
> >>>> HouseColor = c, Drink = d, Order=o, Pet=p, Smoke=s };
> >>>> var validHouses = from h in allHouses
> >>>> where h.IsValid
> >>>> select h;
> >>>> Console.WriteLine("{0} valid houses", validHouses.Count());
> >>>> var streets = from h1 in validHouses
> >>>> where h1.Order == 0
> >>>> join h2 in validHouses on 1 equals h2.Order
> >>>> join h3 in validHouses on 2 equals h3.Order
> >>>> join h4 in validHouses on 3 equals h4.Order
> >>>> join h5 in validHouses on 4 equals h5.Order
> >>>> select new Street(h1, h2, h3, h4, h5);
> >>>> Console.WriteLine("{0} total street permutations.",
> >>>> streets.Count());
> >>>> var result = from s in streets
> >>>> where s.IsValid
> >>>> select s;
> >>>> foreach (Street h in result)
> >>>> {
> >>>> Console.WriteLine(h.DescribeStreet());
> >>>> }
> >>>> Console.ReadKey();
> >>>> }
> >>>> }
> >>>> }
> >>>>> Jordan- Hide quoted text -
> >>>> - Show quoted text -
> >>> 3 seconds... that is even faster than the SQL example. Linq seems to
> >>> have provided the fastest solution yet!
> >>> Does changing the order of the enum lists have any noticeable affect
> >>> on the time?
> >> I'll have to try that tonight. Just to clarify, are you talking about
> >> changing the order of the values within the enums, or changing the order
> >> in which the enums are joined together to form the list of House
> >> permutations? I'm assuming the former.

>
> >> I wouldn't think that it would have any effect, though, because unlike
> >> your code mine iterates over all of the possible Street permutations no
> >> matter what. If I remember correctly yours had a short-circuit where if
> >> it found a valid street it stopped processing, right? Were your
> >> performance differences because of that short circuit, where a correct
> >> answer early in the list of Street permutations short-circuits the rest
> >> of the list?

>
> >>> Jordan- Hide quoted text -
> >> - Show quoted text -- Hide quoted text -

>
> >> - Show quoted text -

>
> > That is correct. It iterates until it finds a valid street and then
> > stops.
> > So you're saying that the Linq solution iterates all streets (no short
> > circuit). If the same validation logic is taking place *more times*
> > in the Linq version, how does Linq make it run so much faster? It
> > still has to loop through and run the validation algorithm.

>
> > Thoughts?

>
> When you timed your solution, did you have the Console.Writeline in each
> iteration? I had your implementation up and running on my machine
> without outputting to the console, and it ran in about the same amount
> of time as the Linq solution.
>
>
>
> > Jordan- Hide quoted text -

>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


Good catch my friend! It is so obvious that I completely overlooked
how much time it adds to display each count on screen! I guess it
just goes to show how much the industry has shifted my emphasis toward
the notion that "visual interface == user satisfaction".

Now my solution runs anywhere between 0 to 1 second. That is pretty
much instantaneous!


Jordan

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 07:42 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.