473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Programmers Contest: Fit pictures on a page

GLOSSY: The Summer Programmer Of The Month Contest is underway!
Deadline is September 30, 2005
http://dinsights.com/POTM
--------------------------------------------------------------------------------
I love taking digital pictures, but that nice glossy photo paper
is expensive! So when my lovely wife asks for prints of a bunch
of pictures, I always try and fit them onto a single piece of paper.

The summer POTM challenges you to write a program that will place up to
26 pictures on a sheet of paper with the least amount of leftover
space.
--------------------------------------------------------------------------------
The Programmer Of The Month (POTM) is a just-for-fun programming
contest with an active forum and over 1100 members (we usually
get 40-50 entries for each POTM challenge). Supported languages
include C/C++/Perl/Ruby/PHP/Python/awk/shell.
Emphasis is on the algorithms and the joy of programming.

If it sounds like fun, please visit at http://dinsights.com/POTM ...
=Fred (a.k.a. The POTM-MASTER)

Jul 19 '05 #1
16 1596
Isn't that an NP-complete problem or am I crazy?

Jul 19 '05 #2


Chung Leong wrote:
Isn't that an NP-complete problem or am I crazy?


That makes it a more realistic challange, doesn't it?

Suppose it was something simple, like calculating a
minimal spanning tree. Every program would produce the
same output. What kind of contest would that be?

Jul 19 '05 #3
Don
Chung Leong wrote:
Isn't that an NP-complete problem or am I crazy?


It is NP complete. Its known as the "cutting stock problem" (aka "Knapsack
problem"). Here's a Wikipedia page that describes it:

http://en.wikipedia.org/wiki/Cutting_stock_problem

There are commerical applications available that "solve" the problem in 2D
for use in the woodworking industry (among others). This is generally done
to minimize waste when cutting down panels (plywood, etc) into smaller
pieces for cabinets, etc.

-Don

Jul 19 '05 #4


Don wrote:
Chung Leong wrote:
Isn't that an NP-complete problem or am I crazy?
It is NP complete. Its known as the "cutting stock problem" (aka "Knapsack
problem"). Here's a Wikipedia page that describes it:

http://en.wikipedia.org/wiki/Cutting_stock_problem

There are commerical applications available that "solve" the problem in 2D
for use in the woodworking industry (among others). This is generally done
to minimize waste when cutting down panels (plywood, etc) into smaller
pieces for cabinets, etc.


Not the same. Read the contest rules. You are allowed to change the
size
and shape (do a certain degree). You certainly can't arbitrarily change
the sizes in a woodworking environment.

-Don


Jul 19 '05 #5
In article <42******@usenet01.boi.hp.com>,
Don <do**********@NOSPAM.hp.com> wrote:
Chung Leong wrote:
Isn't that an NP-complete problem or am I crazy?


It is NP complete. Its known as the "cutting stock problem" (aka "Knapsack
problem"). Here's a Wikipedia page that describes it:

http://en.wikipedia.org/wiki/Cutting_stock_problem

There are commerical applications available that "solve" the problem in 2D
for use in the woodworking industry (among others). This is generally done
to minimize waste when cutting down panels (plywood, etc) into smaller
pieces for cabinets, etc.

-Don


Not just plywood panels, but sheets of paper, bolts of cloth, sheet metal,
plate glass, etc. A slight complication is that some materials have a
preferred orientation (i.e. plywood has a grain, textiles have warp vs.
weft, etc) and some don't (or it doesn't matter for the application).

It gets even more interesting when you're restricted to making cuts that
start at an edge, or go all the way through the sheet to the other side.

My first introduction to the problem was helping my grandmother cut cookies
out of a sheet of dough. I can't think of a better way to get introduced
to higher math :-)
Jul 19 '05 #6
On Wed, 29 Jun 2005 19:43:33 -0400,
Roy Smith <ro*@panix.com> wrote:
Not just plywood panels, but sheets of paper, bolts of cloth, sheet
metal, plate glass, etc. A slight complication is that some materials
have a preferred orientation (i.e. plywood has a grain, textiles have
warp vs. weft, etc) and some don't (or it doesn't matter for the
application). It gets even more interesting when you're restricted to making cuts
that start at an edge, or go all the way through the sheet to the
other side.


I ran into this problem when I worked at a small computer store back in
1979 or 1980. One of our customers owned a plastics plant, and found
such a program, and wanted us to install it and maintain it (on an 8080
or a Z-80 running CP/M, no less).

The first release only did rectangles, and assumed flawless material, so
his first trial was to tell the program about a 4 x 8 foot sheet of
plastic, and ask for two 4 x 4 pieces. The program refused, because a
saw blade has a non-zero width. But he had mis-specified the problem,
because a 4 x 8 sheet of plastic was really a half-inch (or some small
amount) bigger in both directions.

Anyway, after a couple more years and a few more releases, the program
could handle arbitrary polygons, shapes with various types of curved
edges, arbitrary flaws in the material (mostly for knots in sheets of
plywood), and I'm sure a few more things I don't remember right now. It
could also beat his "best guy."

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jul 19 '05 #7
Don
me********@aol.com wrote:


Chung Leong wrote:
Isn't that an NP-complete problem or am I crazy?


That makes it a more realistic challange, doesn't it?

Suppose it was something simple, like calculating a
minimal spanning tree. Every program would produce the
same output. What kind of contest would that be?


I was thinking maybe you could use a genetic algorithm, where the fitness
function would caluclate the amount of waste. I'm not very familar with how
to implement this sort of thing, though.

-Don

Jul 19 '05 #8
Don wrote:
I was thinking maybe you could use a genetic algorithm, where the fitness
function would caluclate the amount of waste. I'm not very familar with how
to implement this sort of thing, though.


This problem is well suited to the abilities of genetic algorithms, and
this would probably be an excellent way to learn more about them, even
if you don't get the best solution.

-Peter
Jul 19 '05 #9
On Thu, 30 Jun 2005 13:09:02 -0400,
Peter Hansen <pe***@engcorp.com> wrote:
This problem is well suited to the abilities of genetic algorithms,
and this would probably be an excellent way to learn more about them,
even if you don't get the best solution.


There's some sort of irony or something in there about not writing the
best genetic algorithm, but I can't quite put my finger on it.

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jul 19 '05 #10
Dan Sommers <me@privacy.net> writes:
There's some sort of irony or something in there about not writing the
best genetic algorithm, but I can't quite put my finger on it.


+1 QOTW :)

--
# Edvard Majakari Software Engineer
# PGP PUBLIC KEY available Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737 469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
Jul 19 '05 #11
Dan Sommers wrote:
Peter Hansen <pe***@engcorp.com> wrote:
This problem is well suited to the abilities of genetic algorithms,
and this would probably be an excellent way to learn more about them,
even if you don't get the best solution.


There's some sort of irony or something in there about not writing the
best genetic algorithm, but I can't quite put my finger on it.


Maybe your irony sensor is getting muddled over the fact that genetic
algorithms generally *don't* find the best solutions, just relatively
good ones. They aren't an exhaustive search, they're basically a random
search with some features thought to focus the search on more fruitful
parts of the solution space, thus optimizing it. Unless *my* irony
processors are malfunctioning, I don't think there's anything ironic
about this. (If anything it looks like the exact opposite of irony, to me.)

-Peter
Jul 19 '05 #12
Peter Hansen said unto the world upon 01/07/2005 11:47:
Dan Sommers wrote:
Peter Hansen <pe***@engcorp.com> wrote:
This problem is well suited to the abilities of genetic algorithms,
and this would probably be an excellent way to learn more about them,
even if you don't get the best solution.


There's some sort of irony or something in there about not writing the
best genetic algorithm, but I can't quite put my finger on it.

Maybe your irony sensor is getting muddled over the fact that genetic
algorithms generally *don't* find the best solutions, just relatively
good ones. They aren't an exhaustive search, they're basically a random
search with some features thought to focus the search on more fruitful
parts of the solution space, thus optimizing it. Unless *my* irony
processors are malfunctioning, I don't think there's anything ironic
about this. (If anything it looks like the exact opposite of irony, to me.)

-Peter


Well, I found it ironic, but only when you add that the genetic
algorithm approach came up in the context of a "best fit" problem.
Survival of the fittest indeed :-)

Best,

Brian vdB

Jul 19 '05 #13
Brian van den Broek wrote:
Well, I found it ironic, but only when you add that the genetic
algorithm approach came up in the context of a "best fit" problem.
Survival of the fittest indeed :-)


Optimization codes don't always succeed. What's the irony?

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 19 '05 #14
Robert Kern said unto the world upon 01/07/2005 17:24:
Brian van den Broek wrote:

Well, I found it ironic, but only when you add that the genetic
algorithm approach came up in the context of a "best fit" problem.
Survival of the fittest indeed :-)

Optimization codes don't always succeed. What's the irony?


Well, the punning on 'fit' (fittest in the sense of "most suitable, or
best adapted", appropriate to Darwinian theory vs. fit in the sense of
"to be of the right measure or proper shape and size for") amused me.

There is at least shades of irony in that the best fit in the
Darwinian sense appropriate to genetic algorithms needn't be the best
fit in the sense of proper size and shape. So, in suitable
circumstances, the meaning of "best fit" in one sense being the
opposite of what was intended in the other. (As in, my sense that it
was ironic didn't reside solely in the genetic algorithm's possible
failure to find the optimal solution, but how the semantic ambiguity
of fit plugs into that in the context of the original problem.) I'd
call that at least semi-irony.

(Yes, I get that the best fit for both evolutionary theory and the
genetic algorithm isn't the absolutely best adapted, but best adapted
as measured relative to the contrast class of available
alternatives--a local maximum if you like.)

All in all, I wish I'd not hit send in the first place. This is
perilously close to sending me into fits ;-)

Best,

Brian vdB
Jul 19 '05 #15
On Friday 01 July 2005 06:25 pm, Brian van den Broek wrote:
All in all, I wish I'd not hit send in the first place. This is
perilously close to sending me into fits ;-)


Well, I thought it was funny, anyway. Of course, not when you
have to explain it. ;-)

I guess you just have to have a strong sense of humor to
appreciate it.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com

Jul 19 '05 #16
Don wrote:
Chung Leong wrote:
Isn't that an NP-complete problem or am I crazy?


It is NP complete. Its known as the "cutting stock problem" (aka "Knapsack
problem"). Here's a Wikipedia page that describes it:

http://en.wikipedia.org/wiki/Cutting_stock_problem

There are commerical applications available that "solve" the problem in 2D
for use in the woodworking industry (among others). This is generally done
to minimize waste when cutting down panels (plywood, etc) into smaller
pieces for cabinets, etc.

-Don


For photos, it's a lot simpler, assuming you only want make standard
size prints (IE: 8x10, 5x7, 4x6, 2.5x3.5). There are a very limited
number of combinations of the standard print sizes which will fit on an
8.5x11 sheet of paper. This could probably be solved pretty easily
with just a lookup table.

Also, you have to remember that paper cost is only part of the equation
when printing photos -- you also have to consider ink costs. In the
stock cutting problem, it's assumed that the cutting cost is
insignificant. Given the insane cartidge costs for inkjet printers,
wasting a little paper -- even expensive paper -- is likely to be a
more economical than wasting ink.

Jul 21 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hicinbothem | last post by:
GLOSSY: The Summer Programmer Of The Month Contest is underway! Deadline is September 30, 2005 http://dinsights.com/POTM...
0
by: Sridhar | last post by:
Hi, We, the students of CEG, Anna University are organizing an online programming contest as part of aBaCus 2005. The contest itself will start on 6th March 2005 at 1:00 pm IST and will end...
0
by: Sridhar | last post by:
Hi, We, the students of CEG, Anna University are organizing an online programming contest as part of aBaCus 2005. The contest itself will start on 6th March 2005 at 1:00 pm IST and will end...
0
by: anujb | last post by:
----------------------------------------------------------------------- We are very Pleased to announce IOPC-05 - The International Online Programming Contest. INTRODUCTION - IOPC is...
0
by: hicinbothem | last post by:
GLOSSY: The Summer Programmer Of The Month Contest is underway! Deadline is September 30, 2005 http://dinsights.com/POTM...
23
by: Doug van Vianen | last post by:
Hi, Is there some way in JavaScript to stop the downloading of pictures from a web page? Thank you. Doug van Vianen
13
by: Jim Carlock | last post by:
I have over a hundred pictures I would like to present. Is it practical to create and parse an array of pictures, picture paths, et al using server-side scripting to accomplish this? I...
0
by: Tom 7 | last post by:
Language lovers: Registration is now open for the 9th Annual ICFP Programming Contest! http://icfpcontest.org/ The contest, associated with the International Conference on Functional...
2
by: nikolayn | last post by:
New open contest Interkub 2007 for web programmers and designers! http://www.interkub.ru
22
by: SETT Programming Contest | last post by:
The SETT Programming Contest: The fastest set<Timplementation Write the fastest set<Timplementation using only standard C++/C. Ideally it should have the same interface like std::set. At least...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.