SHARE
TWEET

Tubes yang Tidak Selesai

a guest Aug 22nd, 2019 3 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. %Tubes yang tidak selesai
  3. function mainDriver()
  4.   %This is the main program that drive the simulation
  5.   %First part is to initialize the farm
  6.   infectiousPeriod = 40; %40 hari utk recover
  7.   infectionChance = 0.3125;
  8.   numCattle = 0;
  9.   numIsolated = 0;
  10.   dirX = [1 -1 0 0];
  11.   dirY = [0 0 -1 1];
  12.   initCattleProbability = input('Berapa peluang di atas sebuah petak ada sapi? Masukkan 0 sampai 1: ');
  13.   if((initCattleProbability < 0) || (initCattleProbability > 1))
  14.     error('Invalid Probability');
  15.   end
  16.   farmNum = input('Ada berapa banyak kandang peternakan? ');
  17.   if(farmNum <= 0)
  18.     error('Invalid input')
  19.   end
  20.   farmWidth = 16;
  21.   farmHeight = 95;
  22.   gapWidth = 2; %panjang gap antar farm
  23.   %border kiri farm = (farmKeBerapa-1) * (farmWidth + gapWidth)
  24.   for i = 1:farmNum
  25.     borderKiri = (i-1) * (farmWidth + gapWidth);
  26.     borderKanan = borderKiri + farmWidth;
  27.     for j = borderKiri:borderKanan
  28.       for k = 1:farmHeight
  29.         getSpawned = randi(ceil(1/initCattleProbability));
  30.         if(getSpawned == 1)
  31.           locX = j;
  32.           locY = k;
  33.           numCattle = numCattle + 1;
  34.           %Ini gw ngapain ya Allah
  35.           arraySapi(numCattle).weight = 60 + randi(40)
  36.           arraySapi(numCattle).daySick = 0;
  37.           arraySapi(numCattle).ageDay = 1;
  38.           arraySapi(numCattle).infected = false;
  39.           arraySapi(numCattle).recovered = false;
  40.           arraySapi(numCattle).isolated = false;
  41.           arraySapi(numCattle).susceptible = true;
  42.           arraySapi(numCattle).posX = locX;
  43.           arraySapi(numCattle).posY = locY;
  44.         end
  45.       end
  46.     end
  47.   end
  48.   %Initialize infected cattle
  49.   infectedCattle = randi(numCattle);
  50.   arraySapi(infectedCattle).infected = true;
  51.   arraySapi(infectedCattle).susceptible = false;
  52.   numInfected = 1;
  53.   numSusceptible = numCattle - 1;
  54.   numRecovered = 0;
  55.   %for debugging purpose
  56.   for i = 1:numCattle
  57.     fprintf('Sapi ke-%i beratnya %i\n',i,arraySapi(i).weight);
  58.     fprintf('Dia ada di posisi (%i,%i)\n',arraySapi(i).posX, arraySapi(i).posY);
  59.   end
  60.   %Sekarang cattle scheduler
  61.   dt = 0.25; %tiap iterasi adalah step sebanyak dt hari
  62.   while(true)
  63.     for i = 1:numCattle
  64.       if(arraySapi(i).weight < 600)
  65.         %SIR
  66.         if((arraySapi(i).infected == true) && (arraySapi(i).daySick > infectiousPeriod))
  67.           arraySapi(i).infected = false;
  68.           arraySapi(i).recovered = true;
  69.           numInfected = numInfected - 1;
  70.           numRecovered = numRecovered + 1;
  71.         elseif(arraySapi(i).infected == true)
  72.           arraySapi(i).daySick = arraySapi(i).daySick + dt;
  73.         elseif(arraySapi(i).susceptible == true)
  74.             %INI GIMANA BIAR JALAN AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  75.             nextToInfected = false;
  76.             for(sapi = 1:numCattle)
  77.               if(nextToInfected == false)
  78.                 for(it = 1:4)
  79.                   if((arraySapi(sapi).posX == arraySapi(i).posX + dirX(it)) && (arraySapi(sapi).posY == arraySapi(i).posY + dirY(it))
  80.                     if(arraySapi(sapi).infected == true)
  81.                       nextToInfected = true;
  82.                     end
  83.                   end
  84.                 end
  85.               end
  86.               if(nextToInfected)
  87.                 isGetInfected = randi(ceil(1/infectionChance));
  88.                 if(isGetInfected == 1)
  89.                   arraySapi(i).infected = true;
  90.                   arraySapi(i).susceptible = false;
  91.                   numInfected = numInfected + 1;
  92.                 end
  93.               end
  94.               %inFarm
  95.               dir = randi(4)
  96.               %let's hope they won't stomp another cattle
  97.               %for the love of God please don't
  98.               arraySapi(i).posX = arraySapi(i).posX + dirX(dir);
  99.               arraySapi(i).posY = arraySapi(i).posY + dirY(dir);
  100.               arraySapi(i).weight = arraySapi(i).weight + 0.5 + 0.25 * rand();
  101.             elseif()
  102.                 %YA ALLAH BUNTU MAU NULIS APA LAGI AAAAAAAAAAAAAA
  103.                 %SOMEBODY PLEASE SAVE ME FROM THIS MONSTROSITY
  104.   end
  105. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top