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! http://forums.devshed.com/attachment...achmentid=7328
take some hints:
iam creat the file by this code - import java.awt.*;
-
-
import javax.swing.*;
-
-
import java.lang.SecurityException;
-
-
import java.util.*;
-
import java.util.Formatter;
-
import java.util.FormatterClosedException;
-
import java.util.NoSuchElementException;
-
import java.util.Scanner;
-
-
import java.io.*;
-
import java.io.FileNotFoundException;
-
import java.io.InputStream;
-
import java.io.OutputStream;
-
import java.io.FileInputStream;
-
import java.io.FileOutputStream;
-
import java.io.FileReader;
-
import java.io.FileNotFoundException;
-
-
public class FittingAllgorithm
-
{
-
int memory,dummycount;
-
int process;
-
int[] bestfit,worstfit,nextfit,firstfit;
-
-
-
-
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 ( SecurityException securityException )
-
{
-
System.err.println(
-
"You do not have write access to this file." );
-
System.exit( 1 );
-
} // end catch
-
catch ( FileNotFoundException filesNotFoundException )
-
{
-
System.err.println( "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.printf(
-
"%s\n%s\n%s\n%s\n%s\n","********************\n\nFitting Algorithem\n\n********************\n\nThis Create By\n",
-
"Khalid Ahmed Almallahy\n20032348\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.printf( "%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.setAccount ( input.nextInt() );
-
record.setaccount1( input.nextInt() );
-
record.setaccount2( input.nextInt() );
-
record.setaccount3( input.nextInt() );
-
-
if ( record.getAccount() > 0 )
-
{
-
// write new record
-
output1.format( "%d %d %d %d \n",
-
record.getAccount(),
-
record.getaccount1(),
-
record.getaccount2(),
-
record.getaccount3() );
-
} // end if
-
else
-
{
-
System.out.println(
-
"Job number must be greater than 0." );
-
} // end else
-
} // end try
-
catch ( FormatterClosedException formatterClosedException )
-
{
-
System.err.println( "Error writing to file." );
-
return;
-
} // end catch
-
catch ( NoSuchElementException elementException )
-
{
-
System.err.println( "Invalid input. Please try again." );
-
input.nextLine(); // discard input so user can try again
-
} // end catch
-
-
System.out.printf( "%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 FileNotFoundException
-
{
-
FittingAllgorithm application = new FittingAllgorithm();
-
-
application.openFile();
-
application.addRecords();
-
application.firstfit();
-
//application.worstfit();
-
//application.bestfit();
-
application.closeFile();
-
} // 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;
-
}
-
}
-
-
-
/////////////////////
-
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
5 2809 JosAH 11,448
Recognized Expert MVP
I was wondering there has to be some standard algorithm to do this kind of thing....any ideas would be appreciated.... Thanks!
Hi, nice to see you back; your problem is a difficult problem to solve; here are
some thoughts about it:
A 'job' has a start time, a time length and a memory requirement. We can describe
it as J(s, t, m). If we do know all parameters s, t and m in advance the problem is
a two dimensional bin packing problem (loosely put: try to fit all those blocks in
the two dimensional TxM rectangle where T is time and M is memory requirement.
This problem is nasty as it is and needs sophisticated (integer) linear solvers
such as iLog's CPlex simplex and interior point plus branch and bound solvers.
Don't take this lightly; it's not stuff for a beginner (no insult intended).
If we *don't* know parameter 's' in advance we're dealing with JIT planning (JIT ==
Just In Time) and there's not much more we can do than indeed apply a simple
first- next- best- or worst fit w.r.t. the memory requirement 'm'; parameter 't' is
fixed so we can't fiddle with that.
I do hope that you're dealing with the second variant because the first variant
takes a lot of processing power and nifty heuristics when if comes to cost factors
if all the requirements are *not* met.
kind regards,
Jos
JosAH 11,448
Recognized Expert MVP
ps. when it comes to those 'fit'algorithms : Donald Knuth already showed in the
'70s that it doesn't matter much: simply takes the simplest algorithm.
kind regards,
Jos
RedSon 5,000
Recognized Expert Expert
I'm confused as to what this OP is actually asking about. They have a bunch of bars on a bar graph that they want to place on a piece of paper but do not want them to overlap? How would best fit work for this? It seems pretty simple, you find the length of the largest bar graph and that becomes the maximum length of one axis plus some padding perhaps. Then you add up the widths of all the bars and that becomes the size of your other axis plus some padding. Then its a matter of placing all your bars on the coordinate plane in some order.
I'm confused.
JosAH 11,448
Recognized Expert MVP
I'm confused as to what this OP is actually asking about. They have a bunch of bars on a bar graph that they want to place on a piece of paper but do not want them to overlap? How would best fit work for this? It seems pretty simple, you find the length of the largest bar graph and that becomes the maximum length of one axis plus some padding perhaps. Then you add up the widths of all the bars and that becomes the size of your other axis plus some padding. Then its a matter of placing all your bars on the coordinate plane in some order.
I'm confused.
It is very simple when the only thing you can do is JIT scheduling, i.e. when a 'job'
arrives you run it asap using one of the fit strategies. When all jobs are submitted
in advance and the amount of memory needed by the job as well as the approximate
runtime, the problem is extremely difficult because the different fit strategies
influence the order of the jobs to be run.
kind regards,
Jos
ps. the OP 'thanked' me for *not* solving his problem so I'm not giving this thing
any more thoughts; it can be an easy problem or it can be extremely nasty; the
OP didn't say what s/he wanted exactly ...
RedSon 5,000
Recognized Expert Expert
It is very simple when the only thing you can do is JIT scheduling, i.e. when a 'job'
arrives you run it asap using one of the fit strategies. When all jobs are submitted
in advance and the amount of memory needed by the job as well as the approximate
runtime, the problem is extremely difficult because the different fit strategies
influence the order of the jobs to be run.
kind regards,
Jos
ps. the OP 'thanked' me for *not* solving his problem so I'm not giving this thing
any more thoughts; it can be an easy problem or it can be extremely nasty; the
OP didn't say what s/he wanted exactly ...
Quite rude of the OP but I think I see what is going on here. They asked for some help parsing their text file and what we gave them was a high level discussion of how to simulate bet fit scheduling of Jobs on a processor. I reviewed the OPs code and I cannot figure out what in the world they are doing. Their code is not indented well and the classes don't really do anything, and whats worse is they break the cardinal rule of creating useful variable names.
The OP wants to know how to (I think) partition their text file into 20 kb chunks. I'm not sure exactly what that means, partition it so that they can write only 20kb per line, or partition it so that there is only 20kb that can be stuck in it at a time, or something else?
If you want to be stingy about the number of KB you are reading or writing to a file you will want to use something like a Bit Stream Reader/Writer. These classes should have methods that allow you to keep a count of the bytes read or written.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: rdsteph |
last post by:
I am having a lot of fun using the pyGoogle module (
http://pygoogle.sourceforge.net/ ) that uses the Google API. It is
about as easy to use as I can imagine, and it is a lot nicer than using
my old HTMl screen scraping habits.
My online CGI program Ask Merlin at www.awaretek.com/askmerlin.html is
an example. Currently, the program takes...
|
by: PWalker |
last post by:
Hi, I have written code that I would like to optimize. I need to push it to
the limit interms of speed as the accuracy of results are proportional to
runtime.
First off, would anyone know any resources that explains how to optimize
code i.e. give some rules on c++ optimization? e.g. using memcpy to copy an
array (which i have done).
...
|
by: Matt Kruse |
last post by:
http://www.JavascriptToolbox.com/bestpractices/
I started writing this up as a guide for some people who were looking for
general tips on how to do things the 'right way' with Javascript. Their code
was littered with document.all and eval, for example, and I wanted to create
a practical list of best practices that they could easily put to...
|
by: Kent |
last post by:
Hi!
I want to store data (of enemys in a game) as a linked list, each node will
look something like the following:
struct node
{
double x,y; // x and y position coordinates
struct enemy *enemydata; // Holds information about an enemy (in a game)
// Its a double linked list node
|
by: nib |
last post by:
What kind of problems is c best at solving?
| |
by: robert |
last post by:
Hello,
I want to put (incrementally) changed/new files from a big file tree
"directly,compressed and password-only-encrypted" to a remote backup
server incrementally via FTP,SFTP or DAV.... At best within a closed
algorithm inside Python without extra shell tools.
(The method should work with any protocol which allows somehow read,
write...
|
by: google |
last post by:
Hi All,
I'm just getting started learning to use <algorithm> instead of loads
of little for loops, and I'm looking for a bit of advice/mentoring re:
implementing the following...
I have a vector of boost::shared_ptr's, some of which may be NULL. I'd
like to find out if there are any non-NULL elements in the vector.
Here's what I have at...
|
by: raylopez99 |
last post by:
What's the best way of implementing a multi-node tree in C++? What I'm
trying to do is traverse a tree of possible chess moves given an intial
position (at the root of the tree). Since every chess position has
around 30 moves, it would mean every node of the tree would have 30
branches (on average), which in turn themselves would average...
|
by: pj |
last post by:
Hi,
I 'm currently writing a program that performs transliteration (i.e.,
converts greek text written using the english alphabet to "pure" greek
text using the greek alphabet) as part of my thesis. I have decided to
add the capability to convert words using some sort of lookup
algorithm as a sidekick to the "normal" conversion algorithm,...
|
by: kamsmartx |
last post by:
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....here'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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |