7 Replies - 694 Views - Last Post: 15 May 2014 - 09:47 AM Rate Topic: -----

#1 Mazer Rackham   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-May 14

Could you help me to understand this program?

Posted 15 May 2014 - 08:41 AM

I'm trying to analyze Population Dynamics. I found some articles and read them but i can't figure out what kind of model i need to use. I tried Forest Fire model but i failed in modificating. I request help for my teacher then he send a sketchy program and said i'm really busy i can't help to much but its the base, edit and organize it for understand. But i can't understand functions and what is he trying to do. Could you explain to me what's going on here?

#include <stdio.h>
#include <stdlib.h>
#define MaxPopulation 10000
#define MaxChildren 10
#define maxAge 70
#define ranf() ((double) random()/(double)RAND_MAX)
#define LifeExp(i) (1.0-((double)MaxAge-i)/(double)MaxAge)
int Children[MaxPopulation][MaxChildren];
int Parents[MaxPopulation][2];
int AddressList[MaxPopulation+1];
void Fill_Population(int InitialPopulation);
void Update_Population();
int main(){

  return(0);
}

void Update_Population(){
  int i,j,k;
  for(i=1;i<=AddressList[0];i++){
    j = AddressList[i];
    Parents[j][0]++;
    Parents[j][1]++;
    for(k=i;Children[j][0];k++)
    	Children[j][k]++;
  }
  for(i=1;i<=AddressList[0];i++){
    if(lifeExp(Parent[i][0]) > ranf())Parent[i][0]=-1;
    if(lifeExp(Parent[i][1]) > ranf())Parent[i][1]=-1;
    for(k=i;Children[j][0];k++)
    	if(lifeExp(Children[j][k])> ranf())
    		Children[j][k]=-1;
}
}


void Update_Mariges(){
  int i,j,k;
  for(i=1;i<=(N=AddressList[0]);i++){
    k = N*ranf()+1;
    l = N*ranf()+1;
    for(j=1;Children[k][0];k++)
    for(m=1;Children[l][0];l++)
Children[k][j] Children[l][m]
  }
}

void Update_Birth(){
  int i,j,k;
  for(i=1;i<=(N=AddressList[0]);i++){
    if(Parent[i][0] < 60 && Parent[i][0] < 60 ){
      if(BirthProbability > ranf()){
       Children[i][0]++;
      Children[i][Children[i][0]]=0;
    }
  }
}
1
void Fill_Population(int InitialPopulation){

   int i,j,k;
  for(i=0;i<MaxPopulation;i++){
    AddressList[i]=0;
    for(j=0;j<MaxChildren;j++){
    	Children[i][j]=0;
    }
  }
  i=0;
  do{
    Adress = MaxPopulation * ranf();
    if(Parents[AdressList][0]==0){
      Parents[AdressList][0]=1;
      Parents[AdressList][1]=1;
      i++;
      AdressList[0]+=1;
      AdressList[i]=Adress;
    }
  }while(i<InitialPopulation);
}




Is This A Good Question/Topic? 0
  • +

Replies To: Could you help me to understand this program?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,809
  • Joined: 12-June 08

Re: Could you help me to understand this program?

Posted 15 May 2014 - 08:43 AM

13	int main(){
14	 
15	  return(0);
16	}


I would imagine, with an empty Main, the program is not doing a whole lot of anything.
Was This Post Helpful? 0
  • +
  • -

#3 Mazer Rackham   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-May 14

Re: Could you help me to understand this program?

Posted 15 May 2014 - 08:49 AM

View Postmodi123_1, on 15 May 2014 - 08:43 AM, said:

13	int main(){
14	 
15	  return(0);
16	}


I would imagine, with an empty Main, the program is not doing a whole lot of anything.


Program is really sketchy. I just want to understand which function is for what.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,809
  • Joined: 12-June 08

Re: Could you help me to understand this program?

Posted 15 May 2014 - 08:54 AM

Actually, no, it is not sketchy. The function names explain, pretty well, what they do. It's not like they are fibbing to you. Basically you fictitious population is held in arrays.. then through cycling through the arrays you are updating children and stats on age/death/etc.

There's two functions used.. why not plug them into the empty main and run a few rounds.. see what it is doing.
Was This Post Helpful? 1
  • +
  • -

#5 Mazer Rackham   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-May 14

Re: Could you help me to understand this program?

Posted 15 May 2014 - 09:13 AM

Yes, functions names explaining its for what, but i can't figure out how. For example; whats going on in the do-while loop? What's the Adress it can't defined, initial population as well. I'm not good at in c programming languagei still learning. I tried to compile piece by piece but still more errors for bluring mt head. Thank you for suggestion by the way.

void Fill_Population(int InitialPopulation){

	   int i,j,k;
	  for(i=0;i<MaxPopulation;i++){
	    AddressList[i]=0;
	    for(j=0;j<MaxChildren;j++){
	    	Children[i][j]=0;
	    }
	  }
	  i=0;
	  do{
	    Adress = MaxPopulation * ranf();
	    if(Parents[AdressList][0]==0){
	      Parents[AdressList][0]=1;
	      Parents[AdressList][1]=1;
	      i++;
	      AdressList[0]+=1;
	      AdressList[i]=Adress;
	    }
	  }while(i<InitialPopulation);
	}

Was This Post Helpful? 0
  • +
  • -

#6 tarmizi_adam2005   User is offline

  • جوروترا

Reputation: 287
  • View blog
  • Posts: 986
  • Joined: 18-April 09

Re: Could you help me to understand this program?

Posted 15 May 2014 - 09:14 AM

Hi,

You might want to at least call some of the functions in your main() function. As modi123_1 already mentioned, an empty main() function pretty much does nothing until you start populating it with some code and those function calls. Then try compiling and and see what output do you get.
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,809
  • Joined: 12-June 08

Re: Could you help me to understand this program?

Posted 15 May 2014 - 09:28 AM

Quote

What's the Adress it can't defined

I don't know. Do you see it defined anywhere? I don't. Is this something you changed? Look at how it is being used and try declaring it a datatype based off a guess of its use.

Quote

initial population as well.

Look at the function.. notice 'intial population' is an incoming variable from where ever you call the method.

Quote

but i can't figure out how

Literally go through each line. They are not cryptic.


What I would recommend is calling a few of those functions, and stepping through (you know, debugging) what is happening.. see what is being filled with which values, etc.
Was This Post Helpful? 0
  • +
  • -

#8 Mazer Rackham   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-May 14

Re: Could you help me to understand this program?

Posted 15 May 2014 - 09:47 AM

I didn't change anything in program. Address thing is really confuse my mind. Now I'm trying to analyze slowly and step by step. Thanks for sparing time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1