<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title><![CDATA[Java Programming Forums - The Java Community - Algorithms & Recursion]]></title>
		<link>http://www.javaprogrammingforums.com/</link>
		<description />
		<language>en</language>
		<lastBuildDate>Sun, 19 May 2013 12:51:32 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.javaprogrammingforums.com/images/misc/rss.png</url>
			<title><![CDATA[Java Programming Forums - The Java Community - Algorithms & Recursion]]></title>
			<link>http://www.javaprogrammingforums.com/</link>
		</image>
		<item>
			<title>Earliest deadline cpu scheduling algorithm</title>
			<link>http://www.javaprogrammingforums.com/algorithms-recursion/29524-earliest-deadline-cpu-scheduling-algorithm.html</link>
			<pubDate>Sat, 18 May 2013 10:34:12 GMT</pubDate>
			<description><![CDATA[I can't figure out how to show the correct diagram for this earliest deadline first algorithm. So far here is my code: 
<div...]]></description>
			<content:encoded><![CDATA[<div>I can't figure out how to show the correct diagram for this earliest deadline first algorithm. So far here is my code:<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">import java.util.*;
&nbsp;
&nbsp;
    class deadlineprototype
    {
&nbsp;
&nbsp;
    public static void main(String args&#91;&#93;)
    {
&nbsp;
&nbsp;
    Scanner sc = new Scanner(System.in);
&nbsp;
&nbsp;
    System.out.println(&quot;enter no. of processes : &quot;);
    int n=sc.nextInt();
    int job&#91;&#93;=new int&#91;n+1&#93;;
    int burst&#91;&#93;=new int&#91;n+1&#93;;
    int newburst&#91;&#93;=new int&#91;n+1&#93;;
    int arrival&#91;&#93;=new int&#91;n+1&#93;;
    int deadline&#91;&#93;=new int&#91;n+1&#93;;
    int wt&#91;&#93;=new int&#91;n+1&#93;;
    int turn&#91;&#93;=new int&#91;n+1&#93;;
    int tot_turn=0;
    int tot_wait=0;
    float avg_turn=0;
    float avg_wait=0;
    int j;
&nbsp;
    for(int m=1;m&lt;=n;m++)
        {
        arrival&#91;m&#93;=m;
        }
    for(int m=1;m&lt;=n;m++)
        {
        job&#91;m&#93;=m;
        }
&nbsp;
    for(int m=1;m&lt;=n;m++)
        {
        System.out.println(&quot;enter arrival time, burst time and deadline of process &quot;+(m)+&quot;(0 for none):&quot;);
        arrival&#91;m&#93;=sc.nextInt();
        burst&#91;m&#93;=sc.nextInt();
        deadline&#91;m&#93;=sc.nextInt();
&nbsp;
    if (deadline&#91;m&#93;==0){
        deadline&#91;m&#93;=1000;
    }
        }
&nbsp;
&nbsp;
&nbsp;
    int temp;
    for(int i=1;i&lt;n;i++)
        {
        for(j=1;j&lt;n;j++)
            {
&nbsp;
                if(deadline&#91;i+1&#93;&lt;deadline&#91;j&#93;)
                {
                temp=deadline&#91;j+1&#93;;
                deadline&#91;j+1&#93;=deadline&#91;j&#93;;
                deadline&#91;j&#93;=temp;
&nbsp;
                temp=job&#91;j+1&#93;;
                job&#91;j+1&#93;=job&#91;j&#93;;
                job&#91;j&#93;=temp;
&nbsp;
                temp=burst&#91;j+1&#93;;
                burst&#91;j+1&#93;=burst&#91;j&#93;;
                burst&#91;j&#93;=temp;
                }
        }
        }
    turn&#91;1&#93;=burst&#91;1&#93;;    
&nbsp;
    for(int i=2;i&lt;=n;i++)
        {
        turn&#91;i&#93;=burst&#91;i&#93;+turn&#91;i-1&#93;;
        wt&#91;i&#93;=turn&#91;i&#93;-burst&#91;i&#93;;
        }
    for(int i=1;i&lt;=n;i++)
        {
        tot_turn+=(wt&#91;i&#93;+burst&#91;i&#93;)-arrival&#91;i&#93;;
        avg_turn=(float)tot_turn/n;
        tot_wait+=wt&#91;i&#93;-arrival&#91;i&#93;;
        avg_wait=(float)tot_wait/n;
        }
    System.out.println(&quot;----------Earliest Deadline Scheduling Diagram----------&quot;);
    for(int m=1;m&lt;=n;m++)
        {
    if(deadline&#91;m&#93;==1000){
            deadline&#91;m&#93;=0;
            }
    if(wt&#91;m&#93;==0){
            System.out.println(&quot;0&quot;+wt&#91;m&#93;+&quot; _____&quot;); 
    }
    else{
    System.out.println(wt&#91;m&#93;+&quot; _____&quot;); 
    }
            System.out.println(&quot;  |     |&quot;);
&nbsp;
            System.out.println(&quot;  |job &quot;+job&#91;m&#93;+&quot;|&quot;);
&nbsp;
            System.out.println(&quot;  |_____|&quot;);
                    try
                 {
                 //newburst&#91;m&#93;=(burst&#91;m&#93;*1000);
                 Thread.sleep(1000);  
                 }catch (InterruptedException ie)
                 {
                 System.out.println(ie.getMessage());
                 }
    }
    System.out.println((wt&#91;wt.length-1&#93;+burst&#91;burst.length-1&#93;));</pre></div></code><hr />
</div> <br />
If I input 2 processes this will be the output:<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">enter no. of processes : 
    2
    enter arrival time, burst time and deadline of process 1(0 for none):
    0 17 0
    enter arrival time, burst time and deadline of process 2(0 for none):
    0 13 10
    ----------Earliest Deadline Scheduling Diagram----------
    00 _____
      |     |
      |job 2|
      |_____|
    13 _____
      |     |
      |job 1|
      |_____|
    30</pre></div></code><hr />
</div> <br />
It shows the correct intended output. But for 3 processes like this then it will output:<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">enter no. of processes : 
    3
    enter arrival time, burst time and deadline of process 1(0 for none):
    0 17 0
    enter arrival time, burst time and deadline of process 2(0 for none):
    0 13 10
    enter arrival time, burst time and deadline of process 3(0 for none):
    25 14 20
    ----------Earliest Deadline Scheduling Diagram----------
    00 _____
      |     |
      |job 2|
      |_____|
    13 _____
      |     |
      |job 3|
      |_____|
    27 _____
      |     |
      |job 1|
      |_____|
    44</pre></div></code><hr />
</div> It shows an incorrect output, that job 1 should come after job 2 and instead of job 3. But then again if I input 5 process it will show correct output again:<br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">enter no. of processes : 
    5
    enter arrival time, burst time and deadline of process 1(0 for none):
    0 17 0
    enter arrival time, burst time and deadline of process 2(0 for none):
    0 13 10
    enter arrival time, burst time and deadline of process 3(0 for none):
    25 14 20
    enter arrival time, burst time and deadline of process 4(0 for none):
    25 10 15
    enter arrival time, burst time and deadline of process 5(0 for none):
    30 5 0
    ----------Earliest Deadline Scheduling Diagram----------
    00 _____
      |     |
      |job 2|
      |_____|
    13 _____
      |     |
      |job 1|
      |_____|
    30 _____
      |     |
      |job 4|
      |_____|
    40 _____
      |     |
      |job 3|
      |_____|
    54 _____
      |     |
      |job 5|
      |_____|
    59</pre></div></code><hr />
</div> And now I wonder what codes is causing the program to show incorrect input. Please help with this problem thanks in advance!</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/algorithms-recursion/"><![CDATA[Algorithms & Recursion]]></category>
			<dc:creator>eraniichan</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/algorithms-recursion/29524-earliest-deadline-cpu-scheduling-algorithm.html</guid>
		</item>
		<item>
			<title>How to specify the number of processors to use in each round of execution in a multicore environment</title>
			<link>http://www.javaprogrammingforums.com/algorithms-recursion/29431-how-specify-number-processors-use-each-round-execution-multicore-environment.html</link>
			<pubDate>Mon, 13 May 2013 15:03:35 GMT</pubDate>
			<description>Hello, I already know how to use the runtime method to get the number of available processors but what I need is how to control the number of...</description>
			<content:encoded><![CDATA[<div>Hello, I already know how to use the runtime method to get the number of available processors but what I need is how to control the number of processors to be used during each round of test or execution in a multicore environment. <br />
Put differently, I want to experiment on one node of a multicore computer with  12processors, but I need to be able to specify at each round of the experiment (execution) how many processors should execute my threaded application. I need to be able to specify the use of 2 cpus, 4 cpus, 6 cpus,8 cpus, 10 cpus and 12 cpus. <br />
Any suggestion will be welcome<br />
Thanks</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/algorithms-recursion/"><![CDATA[Algorithms & Recursion]]></category>
			<dc:creator>atgoodprogram</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/algorithms-recursion/29431-how-specify-number-processors-use-each-round-execution-multicore-environment.html</guid>
		</item>
		<item>
			<title>Help With Diamond Square Terrain</title>
			<link>http://www.javaprogrammingforums.com/algorithms-recursion/29138-help-diamond-square-terrain.html</link>
			<pubDate>Sat, 04 May 2013 10:16:58 GMT</pubDate>
			<description><![CDATA[This code may be difficult to understand but basically I'm just trying to do the diamond square algorithm to make some terrain for a tile based game....]]></description>
			<content:encoded><![CDATA[<div>This code may be difficult to understand but basically I'm just trying to do the diamond square algorithm to make some terrain for a tile based game. I never found an example of this for a tiled game so I painstakingly converted someones midpoint displacement, that was for values between 1.0 &amp; 0.0, to all positive numbers and whole number. I also fixed it for diamond square but im not sure if im doing that right. The 4 points of the diamond are actually 3 but i added the midpoint twice cause I didn't want to wrap. I feel like its not doing all the steps properly and in the pixel mode that i have as default atm shows diamond and square artifacts and even can be seen sometimes from the more zoomed in version too. One thing anyone would notice if they are familiar would be the fact a don't have a starting noise value and having it decrease after each completion (I am having trouble in this area too). For each step it is adding plus or minus 1. At the way bottom of the code is the keyboard handler and it set noise to 4 for now, clears the array, and makes new corner values after pressing spacebar. If someone can see if I did the diamond square wrong and have any tips for generating these numbers for a tile based game that would be awesome. The decimal places were making it difficult for me but I might go back and use em again but just times the height value by 10 or 100 to bump it up to something I may find more usable.<br />
 <br />
<div class="bbcode_container">
                <div class="bbcode_description">Code :</div>
                <hr /><code class="bbcode_code"><div class="" style="font-family:monospace;"><pre style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">package bttg;
&nbsp;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.applet.*;
&nbsp;
&nbsp;
&nbsp;
@SuppressWarnings(&quot;serial&quot;)
public class BTTG extends Applet implements KeyListener, MouseListener, FocusListener{
		short i = 0;
		int worldSize = 499; //99       &lt;-------------------
		int&#91;&#93;&#91;&#93; map = new int&#91;worldSize+1&#93;&#91;worldSize+1&#93;;	
		boolean focussed = false;
		short rand;
		double noise = 0;
&nbsp;
&nbsp;
	public void init()
	{
		addKeyListener(this);
&nbsp;
	}
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	public boolean squareStep(int x, int y, int x1, int y1) //Diamond and Square Steps
	{
&nbsp;
		if(x1-x&lt;2 &amp;&amp; y1-y&lt;2) return false;
		int sideMidX = (x+x1)/2;
		int sideMidY = (y+y1)/2;
&nbsp;
&nbsp;
		rand = (byte) (Math.random()*noise - (noise/2));  // These values are locked at the moment      random()*4 - (4/2); .... creates -1 to 1. 2 -1 wasn't working;  Try doing 6 - (6/2) for more bumpy terrain
		if(map&#91;sideMidX&#93;&#91;sideMidY&#93; == 0) map&#91;sideMidX&#93;&#91;sideMidY&#93; = Math.abs((map&#91;x&#93;&#91;y&#93; + map&#91;x&#93;&#91;y1&#93; + map&#91;x1&#93;&#91;y&#93; + map&#91;x1&#93;&#91;y1&#93;)/4 + (int)rand);  // Diamond
&nbsp;
&nbsp;
		rand = (byte) (Math.random()*noise - (noise/2));
		if(map&#91;x&#93;&#91;sideMidY&#93; == 0)  map&#91;x&#93;&#91;sideMidY&#93; = Math.abs((map&#91;x&#93;&#91;y1&#93; + map&#91;x&#93;&#91;y&#93; + map&#91;sideMidX&#93;&#91;sideMidY&#93; + (map&#91;sideMidX&#93;&#91;sideMidY&#93;)+rand)/4) + (int) rand);  // Left side Squares or other way around\/\/\/ 
// Having these at + 0 noise make really flat terrain which isnt bad  either
&nbsp;
&nbsp;
		rand = (byte) (Math.random()*noise - (noise/2));
		if(map&#91;sideMidX&#93;&#91;y&#93; == 0)  map&#91;sideMidX&#93;&#91;y&#93; = Math.abs((map&#91;x1&#93;&#91;y&#93; + map&#91;x&#93;&#91;y&#93; + map&#91;sideMidX&#93;&#91;sideMidY&#93; + (map&#91;sideMidX&#93;&#91;sideMidY&#93;)+rand)/4) + (int) rand; // Top Side
&nbsp;
&nbsp;
		rand = (byte) (Math.random()*noise - (noise/2));
		if(map&#91;sideMidX&#93;&#91;y1&#93; == 0)  map&#91;sideMidX&#93;&#91;y1&#93; = Math.abs((map&#91;x&#93;&#91;y1&#93; + map&#91;x1&#93;&#91;y1&#93; + map&#91;sideMidX&#93;&#91;sideMidY&#93; + (map&#91;sideMidX&#93;&#91;sideMidY&#93;)+rand)/4) + (int) rand; // Right Side
&nbsp;
		rand = (byte) (Math.random()*noise - (noise/2));
		if(map&#91;x1&#93;&#91;sideMidY&#93; == 0)  map&#91;x1&#93;&#91;sideMidY&#93; = Math.abs((map&#91;x1&#93;&#91;y&#93; + map&#91;x1&#93;&#91;y1&#93; + map&#91;sideMidX&#93;&#91;sideMidY&#93; + (map&#91;sideMidX&#93;&#91;sideMidY&#93;)+rand)/4) + (int) rand; 
&nbsp;
&nbsp;
		squareStep(x,y,sideMidX,sideMidY);	
		squareStep(sideMidX,y,x1,sideMidY);
		squareStep(x,sideMidY,sideMidX,y1);
		squareStep(sideMidX,sideMidY,x1,y1);
&nbsp;
&nbsp;
	    return true;
	}
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	public void paint(Graphics g)
	{
&nbsp;
&nbsp;
	int x=0;
	int y=0;
&nbsp;
	g.setColor(Color.BLACK);
	g.fillRect(0,0,1920,1080);
	Font mapFont = new Font (&quot;Monospaced&quot;, Font.BOLD, 8); // Not used this is to check the numbers below change to 12 if you want to see values
	g.setFont(mapFont);
	int xMap = 0;
	int yMap = 0; // for numbers change this to 15
&nbsp;
&nbsp;
	while(y&lt;worldSize+1)
	{   
		Color bum = new Color(map&#91;x&#93;&#91;y&#93;, map&#91;x&#93;&#91;y&#93;,map&#91;x&#93;&#91;y&#93;); // makes white shaded array values(times each one by 5 if displaying array values)
		g.setColor(bum); // sets that color
		g.fillRect(xMap, yMap,1,1);   //change this g.draw(&quot;&quot; + map&#91;x&#93;&#91;y&#93; ,xMap, yMap); to change from pixels to numbers (dont forget to change the others too and also change mapSize to 99 at the top
		xMap += 1; // for numbers change this to 15
		x++;
&nbsp;
		if(x == worldSize+1) 
		{		
			x=0;
			y++;
			xMap =0;
			yMap += 1; // for numbers change this to 15
		}
		}
	}
&nbsp;
	public void keyPressed(KeyEvent evt) 
	{
		int key = evt.getKeyCode(); 
&nbsp;
		if (key == KeyEvent.VK_SPACE)        //Space makes a new map
		{
			int x = 0,y = 0;
			noise = 4;
			while(y&lt;worldSize+1)
			{   
				map&#91;x&#93;&#91;y&#93; = 0;
				x++;
&nbsp;
				if(x == worldSize+1)
				{		
					x=0;
					y++;
				}
&nbsp;
			}
&nbsp;
			rand = (short) ((Math.random()*(worldSize/2)));  // \/\/\/\/ These generate the starting corners
			map&#91;0&#93;&#91;0&#93; = rand;
			rand = (short) ((Math.random()*(worldSize/2))); 
			map&#91;worldSize&#93;&#91;0&#93; = rand;
			rand = (short) ((Math.random()*(worldSize/2)));
			map&#91;0&#93;&#91;worldSize&#93; = rand;
			rand = (short) ((Math.random()*(worldSize/2)));
			map&#91;worldSize&#93;&#91;worldSize&#93; = rand;
&nbsp;
			 // rand = (short) ((Math.random()*(worldSize/2)));  // Take comments of to also place one midpoint seed
			// map&#91;worldSize/2&#93;&#91;worldSize/2&#93; = rand;
&nbsp;
&nbsp;
			squareStep(0,0,worldSize,worldSize);
			repaint();
		}
	}
&nbsp;
	public void keyReleased(KeyEvent evt) { }
	public void keyTyped(KeyEvent evt) { char ch = evt.getKeyChar();}
	public void mousePressed(MouseEvent evt) {requestFocus(); System.out.println(&quot;Mouse Works&quot;);}        
	public void focusLost(FocusEvent evt) {focussed = false;}
	public void focusGained(FocusEvent evt) {focussed = true; System.out.println(&quot;We Have Focus&quot;);}
	public void mouseEntered(MouseEvent evt) { }  
	public void mouseExited(MouseEvent evt) { }  
	public void mouseReleased(MouseEvent evt) { } 
	public void mouseClicked(MouseEvent evt) { }
&nbsp;
&nbsp;
}</pre></div></code><hr />
</div> </div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/algorithms-recursion/"><![CDATA[Algorithms & Recursion]]></category>
			<dc:creator>hobbles</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/algorithms-recursion/29138-help-diamond-square-terrain.html</guid>
		</item>
		<item>
			<title>RECURSION</title>
			<link>http://www.javaprogrammingforums.com/algorithms-recursion/28229-recursion.html</link>
			<pubDate>Sat, 20 Apr 2013 08:24:41 GMT</pubDate>
			<description><![CDATA[Could someone explain recursion to me please. I get that a function loops coz  it is called several times but I can't get why and how! Frustration.]]></description>
			<content:encoded><![CDATA[<div>Could someone explain recursion to me please. I get that a function loops coz  it is called several times but I can't get why and how! Frustration.</div>

]]></content:encoded>
			<category domain="http://www.javaprogrammingforums.com/algorithms-recursion/"><![CDATA[Algorithms & Recursion]]></category>
			<dc:creator>kevthanewversi</dc:creator>
			<guid isPermaLink="true">http://www.javaprogrammingforums.com/algorithms-recursion/28229-recursion.html</guid>
		</item>
	</channel>
</rss>
