I'm new to programming and need some help figuring out an algorithm.
I need to design some kind of algorithm which will help us define capacity for one of our portfolios....h ere's the problem explained (also see attached example):
1. The graph defines total capacity, y-axis being $, x-axis being date/time. the bars on the graph represent individual items.
2. What I need to do is place the items on the graph in an optimized manner, minimizing wastage of space. I can break the items vertically but can't break them up horizontally. The goal is to leave as much free space as possible for bigger horizonal items.
3. Items can't overlap each other.
4. See example, I'm currently doing in Access....my procedure takes too long to run and results in overlapped data.
I was wondering there has to be some standard algorithm to do this kind of thing....any ideas would be appreciated.... Thanks!
take some hints:
iam creat the file by this code
[CODE=java] import java.awt.*;
import javax.swing.*;
import java.lang.Secur ityException;
import java.util.*;
import java.util.Forma tter;
import java.util.Forma tterClosedExcep tion;
import java.util.NoSuc hElementExcepti on;
import java.util.Scann er;
import java.io.*;
import java.io.FileNot FoundException;
import java.io.InputSt ream;
import java.io.OutputS tream;
import java.io.FileInp utStream;
import java.io.FileOut putStream;
import java.io.FileRea der;
import java.io.FileNot FoundException;
public class FittingAllgorit hm
{
int memory,dummycou nt;
int process;
int[] bestfit,worstfi t,nextfit,first fit;
private Formatter output1; // object used to output text to file
// enable user to open file
public void openFile()
{
try
{
output1 = new Formatter( "memory.txt " );
} // end try
catch ( SecurityExcepti on securityExcepti on )
{
System.err.prin tln(
"You do not have write access to this file." );
System.exit( 1 );
} // end catch
catch ( FileNotFoundExc eption filesNotFoundEx ception )
{
System.err.prin tln( "Error creating file." );
System.exit( 1 );
} // end catch
} // end method openFile
// add records to file
public void addRecords()
{
// object to be written to file
Job record = new Job();
Scanner input = new Scanner( System.in );
System.out.prin tf(
"%s\n%s\n%s\n%s \n%s\n","****** **************\ n\nFitting Algorithem\n\n* *************** ****\n\nThis Create By\n",
"Khalid Ahmed Almallahy\n2003 2348\n\n******* *************\n ",
"Supervesor by",
"\nMoamar Elyazgi.\n\n*** *************** **\n\n",
"Hint :- \n When You Wont to Exit Press <CTRL>+z\n\n=== =============== =============== =============== ========\n\n" );
System.out.prin tf( "%s\n%s\n",
"Enter First Jop 'Process' number must be greater than 0\n Second Job 'Process'\n Third Job 'Process'\n last Job 'Process'",
"?" );
while ( input.hasNext() ) // loop until end-of-file indicator
{
try // output values to file
{
// retrieve data to be output
record.setAccou nt ( input.nextInt() );
record.setaccou nt1( input.nextInt() );
record.setaccou nt2( input.nextInt() );
record.setaccou nt3( input.nextInt() );
if ( record.getAccou nt() > 0 )
{
// write new record
output1.format( "%d %d %d %d \n",
record.getAccou nt(),
record.getaccou nt1(),
record.getaccou nt2(),
record.getaccou nt3() );
} // end if
else
{
System.out.prin tln(
"Job number must be greater than 0." );
} // end else
} // end try
catch ( FormatterClosed Exception formatterClosed Exception )
{
System.err.prin tln( "Error writing to file." );
return;
} // end catch
catch ( NoSuchElementEx ception elementExceptio n )
{
System.err.prin tln( "Invalid input. Please try again." );
input.nextLine( ); // discard input so user can try again
} // end catch
System.out.prin tf( "%s %s\n%s", "\nEnter First Job'Process' number greater than 0,",
"\nSecond Job 'Process', \nTherd Job 'Process' \nand So on..", "?\n" );
} // end while
} // end method addRecords
// close file
public void closeFile()
{
if ( output1 != null )
output1.close() ;
} // end method closeFile
public void firstfit()
{
Job record = new Job();
Scanner input = new Scanner( System.in );
}
public static void main( String args[] ) throws FileNotFoundExc eption
{
FittingAllgorit hm application = new FittingAllgorit hm();
application.ope nFile();
application.add Records();
application.fir stfit();
//application.wor stfit();
//application.bes tfit();
application.clo seFile();
} // end main
} // end class CreateTextFile
/////////////////
and this one
public class Job
{
private int account;
private int account1;
private int account2;
private int account3;
public Job()
{
// constructor
}
public Job( int acct, int account11, int account22, int account33 )
{
setAccount( acct );
setaccount1( account11 );
setaccount2( account22 );
setaccount3( account33 );
}
public void setAccount( int acct )
{
account = acct;
}
public int getAccount()
{
return account;
}
public void setaccount1( int account11 )
{
account1 = account11;
}
public int getaccount1()
{
return account1;
}
public void setaccount2( int account22 )
{
account2 = account22;
}
public int getaccount2()
{
return account2;
}
public void setaccount3( int account33 )
{
account3 = account33;
}
public int getaccount3()
{
return account3;
}
}
/////////////////////
[/CODE]
but the problem is how can i division the memory text, the memory text i created but i cannot division it
i wont to division it in to 7 parts each part have 20kb
how can i write this code
if there any one helpe me or any one can write code to division this problem
///////////////////
so i wont to enter number to saved it on the memory text
the memory text have 140kb division into 7 parts each part have 20kb
this is my proble
place help me by wite a code ...
////////////////////////////
i wont to division the memory into 7 parts each part have 20kb so the memory have 140kb , then i wont to enter the nuber into the memory text we must search the hole on the memory that is
empty to enter the number and put it in this hole
there r many algorithem to insert and search the hole but i wont to use the first , best, worst fit algorithems
how can i use this fitting by using this code
hint :::
Satisfy request of size n from list of free holes – four basic methods:
First-fit: Allocate the first hole that is big enough.
Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole.
Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole.
help me
I need to design some kind of algorithm which will help us define capacity for one of our portfolios....h ere's the problem explained (also see attached example):
1. The graph defines total capacity, y-axis being $, x-axis being date/time. the bars on the graph represent individual items.
2. What I need to do is place the items on the graph in an optimized manner, minimizing wastage of space. I can break the items vertically but can't break them up horizontally. The goal is to leave as much free space as possible for bigger horizonal items.
3. Items can't overlap each other.
4. See example, I'm currently doing in Access....my procedure takes too long to run and results in overlapped data.
I was wondering there has to be some standard algorithm to do this kind of thing....any ideas would be appreciated.... Thanks!
take some hints:
iam creat the file by this code
[CODE=java] import java.awt.*;
import javax.swing.*;
import java.lang.Secur ityException;
import java.util.*;
import java.util.Forma tter;
import java.util.Forma tterClosedExcep tion;
import java.util.NoSuc hElementExcepti on;
import java.util.Scann er;
import java.io.*;
import java.io.FileNot FoundException;
import java.io.InputSt ream;
import java.io.OutputS tream;
import java.io.FileInp utStream;
import java.io.FileOut putStream;
import java.io.FileRea der;
import java.io.FileNot FoundException;
public class FittingAllgorit hm
{
int memory,dummycou nt;
int process;
int[] bestfit,worstfi t,nextfit,first fit;
private Formatter output1; // object used to output text to file
// enable user to open file
public void openFile()
{
try
{
output1 = new Formatter( "memory.txt " );
} // end try
catch ( SecurityExcepti on securityExcepti on )
{
System.err.prin tln(
"You do not have write access to this file." );
System.exit( 1 );
} // end catch
catch ( FileNotFoundExc eption filesNotFoundEx ception )
{
System.err.prin tln( "Error creating file." );
System.exit( 1 );
} // end catch
} // end method openFile
// add records to file
public void addRecords()
{
// object to be written to file
Job record = new Job();
Scanner input = new Scanner( System.in );
System.out.prin tf(
"%s\n%s\n%s\n%s \n%s\n","****** **************\ n\nFitting Algorithem\n\n* *************** ****\n\nThis Create By\n",
"Khalid Ahmed Almallahy\n2003 2348\n\n******* *************\n ",
"Supervesor by",
"\nMoamar Elyazgi.\n\n*** *************** **\n\n",
"Hint :- \n When You Wont to Exit Press <CTRL>+z\n\n=== =============== =============== =============== ========\n\n" );
System.out.prin tf( "%s\n%s\n",
"Enter First Jop 'Process' number must be greater than 0\n Second Job 'Process'\n Third Job 'Process'\n last Job 'Process'",
"?" );
while ( input.hasNext() ) // loop until end-of-file indicator
{
try // output values to file
{
// retrieve data to be output
record.setAccou nt ( input.nextInt() );
record.setaccou nt1( input.nextInt() );
record.setaccou nt2( input.nextInt() );
record.setaccou nt3( input.nextInt() );
if ( record.getAccou nt() > 0 )
{
// write new record
output1.format( "%d %d %d %d \n",
record.getAccou nt(),
record.getaccou nt1(),
record.getaccou nt2(),
record.getaccou nt3() );
} // end if
else
{
System.out.prin tln(
"Job number must be greater than 0." );
} // end else
} // end try
catch ( FormatterClosed Exception formatterClosed Exception )
{
System.err.prin tln( "Error writing to file." );
return;
} // end catch
catch ( NoSuchElementEx ception elementExceptio n )
{
System.err.prin tln( "Invalid input. Please try again." );
input.nextLine( ); // discard input so user can try again
} // end catch
System.out.prin tf( "%s %s\n%s", "\nEnter First Job'Process' number greater than 0,",
"\nSecond Job 'Process', \nTherd Job 'Process' \nand So on..", "?\n" );
} // end while
} // end method addRecords
// close file
public void closeFile()
{
if ( output1 != null )
output1.close() ;
} // end method closeFile
public void firstfit()
{
Job record = new Job();
Scanner input = new Scanner( System.in );
}
public static void main( String args[] ) throws FileNotFoundExc eption
{
FittingAllgorit hm application = new FittingAllgorit hm();
application.ope nFile();
application.add Records();
application.fir stfit();
//application.wor stfit();
//application.bes tfit();
application.clo seFile();
} // end main
} // end class CreateTextFile
/////////////////
and this one
public class Job
{
private int account;
private int account1;
private int account2;
private int account3;
public Job()
{
// constructor
}
public Job( int acct, int account11, int account22, int account33 )
{
setAccount( acct );
setaccount1( account11 );
setaccount2( account22 );
setaccount3( account33 );
}
public void setAccount( int acct )
{
account = acct;
}
public int getAccount()
{
return account;
}
public void setaccount1( int account11 )
{
account1 = account11;
}
public int getaccount1()
{
return account1;
}
public void setaccount2( int account22 )
{
account2 = account22;
}
public int getaccount2()
{
return account2;
}
public void setaccount3( int account33 )
{
account3 = account33;
}
public int getaccount3()
{
return account3;
}
}
/////////////////////
[/CODE]
but the problem is how can i division the memory text, the memory text i created but i cannot division it
i wont to division it in to 7 parts each part have 20kb
how can i write this code
if there any one helpe me or any one can write code to division this problem
///////////////////
so i wont to enter number to saved it on the memory text
the memory text have 140kb division into 7 parts each part have 20kb
this is my proble
place help me by wite a code ...
////////////////////////////
i wont to division the memory into 7 parts each part have 20kb so the memory have 140kb , then i wont to enter the nuber into the memory text we must search the hole on the memory that is
empty to enter the number and put it in this hole
there r many algorithem to insert and search the hole but i wont to use the first , best, worst fit algorithems
how can i use this fitting by using this code
hint :::
Satisfy request of size n from list of free holes – four basic methods:
First-fit: Allocate the first hole that is big enough.
Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole.
Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole.
help me
Comment