Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » trouble conceptualialising a problem


trouble conceptualialising a problem

Reply
  #1 (permalink)  
Old 10-01-10, 08:38 AM
m.timoney's Avatar
m.timoney m.timoney is offline
Newbie Coder
 
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
trouble conceptualialising a problem

i've a problem and having trouble getting my head around how to find the solution

I have 2 2D arrays the 2nd dependent on the 1st

the first array would by something like
1 1 1 1 2 1 2 3 1 0 1 3 1 0 2 0 0 1 2 2 0 1 1 0 3 4 2 0
0 0 3 0 2 0 2 3 1 2 2 2 2 2 3 3 1 2 1 0 0 0 1 2 2 1 0 2
0 1 1 0 1 1 3 1 3 2 4 1 0 2 3 4 1 1 1 2 2 1 2 2 2 2 1 0
2 1 0 1 2 2 3 1 0 2 2 1 1 2 1 0 3 1 2 0 2 1 1 2 0 1 3 3
2 1 3 1 2 3 2 0 0 1 1 2 2 1 0 2 3 3 1 0 3 3 2 2 0 1 2 1
3 1 0 0 2 0 1 2 3 0 1 2 1 2 2 1 0 2 2 2 2 1 0 2 0 2 0 1
2 1 2 0 1 2 0 0 2 2 2 2 3 1 1 1 0 1 2 3 2 3 3 1 2 1 3 1
1 2 0 0 1 0 4 3 1 2 2 1 2 2 2 0 1 1 3 1 3 2 2 4 2 0 2 1
1 0 2 0 1 1 0 2 0 3 2 2 2 2 3 1 2 0 2 2 2 1 2 0 1 2 0 1
2 0 2 1 0 0 2 1 2 1 2 3 3 1 1 4 0 2 1 2 1 1 2 2 0 3 3 1
2 1 0 2 3 3 1 3 2 2 0 2 2 0 2 3 1 3 3 3 1 4 2 0 3 1 2 1
1 1 0 1 0 0 2 3 2 1 1 3 0 1 1 2 2 1 3 3 3 2 2 0 0 2 3 0
0 2 2 0 2 1 1 0 2 0 3 2 3 0 3 0 1 0 2 2 0 1 2 2 1 2 1 0
4 0 0 1 0 2 1 1 2 2 1 2 3 2 2 2 0 2 2 1 2 2 1 1 3 0 1 2


now where the value in the above array is less than 2 the value in the second grid is 100
otherwise the value is calculated from the surrounding values dependent on the
id the difference between the number that is next to it in the first grid is <2 then 10% rounded down to the nearest int is added to the value of the 2nd array
if the difference is >=2 then 5% is added

so

so if the first array looked like
1 1 1
1 3 1
1 1 1

then the 2nd array would be
100 100 100
100 40 100
100 100 100

ie 100 hundred for every 1 under 2 and the 3 is 5% of each surrounding value

however if it was
1 1 1 1
1 3 3 1
1 3 3 1
1 1 1 1

then each of the 3's values is dependent on the value in each of the other 3's

and i can't think of any way of solving this without ending up in a recursive loop or wrong values

Can anyone help either figure out the maths or the code for that?
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.

Last edited by m.timoney; 10-01-10 at 09:06 AM.
Reply With Quote
  #2 (permalink)  
Old 10-01-10, 09:23 AM
m.timoney's Avatar
m.timoney m.timoney is offline
Newbie Coder
 
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
ok this is just me thinking out loud trying to work on that solution but the thinking might help you help me

doing the calc for the above example manually

each of the 3's gets a base value of 25 from the surrounding <2
@ 25 they leach 2 from the surrounding 3's raising them to 31
@31 they leach 3 from the surrounding 3's raising them to 34 as 2 was already added
@34 they are still leaching 3 so nothing needs to change
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.

Last edited by m.timoney; 10-01-10 at 09:25 AM.
Reply With Quote
  #3 (permalink)  
Old 10-01-10, 09:33 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
I have a hard time to understand exactly what you are trying to acomplish? Does this serve an actual purpose? If so what is it? or is it more a programmer puzzle

Can you post any code you have so far?
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #4 (permalink)  
Old 10-01-10, 10:09 AM
m.timoney's Avatar
m.timoney m.timoney is offline
Newbie Coder
 
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
i've simplified the numbers to make it easier to understand as its the process i'm stuggling with and that doesn't change what ever the figures and this is only a sub section of the overall problem.

basically its a very simplified model of how a liquid diffuses though a permeable solid
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.

Last edited by m.timoney; 10-01-10 at 10:18 AM.
Reply With Quote
  #5 (permalink)  
Old 10-04-10, 08:37 AM
m.timoney's Avatar
m.timoney m.timoney is offline
Newbie Coder
 
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
as for code so far there isn't any, until i can get my head round what i need to do then writing code is impossible
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.
Reply With Quote
  #6 (permalink)  
Old 10-04-10, 03:32 PM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Sorry for not replying yet. First of I'm still on vacation, so in slow mode but second I am having a hard time figuring this out. Am still looking though.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #7 (permalink)  
Old 10-05-10, 04:07 AM
m.timoney's Avatar
m.timoney m.timoney is offline
Newbie Coder
 
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
lol no worries i fully understand thats why i'm here in the first place.

i'm currently trying to model the manual process inorder to duplicate it that way
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.
Reply With Quote
  #8 (permalink)  
Old 10-05-10, 06:16 AM
m.timoney's Avatar
m.timoney m.timoney is offline
Newbie Coder
 
Join Date: Jan 2007
Location: Leicester - UK
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
here's what i have now
Code:
    public class humidifier
    {
        private Dictionary<Tile, Dictionary<Tile, int>> changes;
        private List<Tile> water;
        private Map map;
        public humidifier(Map map)
        {
            this.map = map;

            changes = new Dictionary<Tile, Dictionary<Tile, int>>();
            water = new List<Tile>();
            for (int y = 0; y < map.Size[1]; y++)
            {
                for (int x = 0; x < map.Size[0]; x++)
                {
                    changes.Add(map[x, y], new Dictionary<Tile, int>());
                    if (map[x, y].IsWet) water.Add(map[x, y]);
                    for (int j = -1; j <= 1; j++)
                    {
                        if (y + j >= 0 && y + j < map.Size[1])
                        {
                            for (int i = -1; i <= 1; i++)
                            {
                                if (!(i == 0 && j == 0))
                                {

                                    int tmpx = x + i;
                                    if (tmpx < 0)
                                    {
                                        tmpx = map.Size[0] - 1;
                                    }
                                    if (tmpx > map.Size[0] - 1)
                                    {
                                        tmpx = 0;
                                    }
                                    if (!map[tmpx, y + j].IsWet)
                                    {
                                        changes[map[x, y]].Add(map[tmpx, y + j], 0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public void Run()
        {
            foreach (Tile t in water)
            {
                Wet(t);
            }
        }
        private void Wet(Tile source)
        {
            List<Tile>tmplist = changes[source].Keys.ToList();
            foreach (Tile target in tmplist)
            {
                int changesofar = changes[source][target];
                double changefactor = .1 -  (target.Level- source.Level) * .05;

                int nextchange = (int)(source.Humidity * changefactor);
                nextchange -=changesofar;
                if (nextchange > 0)
                {
                    target.Humidity += nextchange;
                    changes[source][target] += nextchange;
                    Wet(target);
                }
            }
        }
    }
its basically modelling the manual way i did the calculation and i think that its working

so unless you can improve it i think i'm sorted
__________________
Definition of a Beginner, Someone who doesn't know the rules.

Definition of an Expert, Someone who knows when to ignore the rules.

Last edited by m.timoney; 10-05-10 at 06:19 AM.
Reply With Quote
  #9 (permalink)  
Old 10-07-10, 05:08 PM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Well can't really see anything wrong with it. Then again I don;t see the Classes Map and Tile.

Dont know if you are having any performance issues or something with large arrays. If so, just post the 2 other classes too
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unknown Javascript/Ajax problem vitron JavaScript 9 06-05-09 11:44 AM
Pls help website problem! iangarrinud CSS 1 01-03-08 01:48 PM
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
Form Display Problem neevrap02 Visual Basic 1 09-05-06 05:18 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 09:13 AM


All times are GMT -5. The time now is 02:19 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.