packing

Packing rectangles for compact representation

做~自己de王妃 提交于 2019-11-30 21:23:06
I am looking for pointers to the solution of the following problem: I have a set of rectangles, whose height is known and x-positions also and I want to pack them in the more compact form. With a little drawing (where all rectangles are of the same width, but the width may vary in real life), i would like, instead of. -r1- -r2-- -r3-- -r4- -r5-- something like. -r1- -r3-- -r2-- -r4- -r5-- All hints will be appreciated. I am not necessarily looking for "the" best solution. Your problem is a simpler variant, but you might get some tips reading about heuristics developed for the "binpacking"

Fitting rectangles together in optimal fashion

筅森魡賤 提交于 2019-11-30 18:33:32
I was wondering if anyone knows of any algorithms suited to fitting together N number of rectangles of unknown size into the smallest possible containing rectangle. By optimal I mean with reducing the amount of white space left over in the resulting containing rectangle. I would like to use this to generate css sprites from a series of images. Many Thanks, Ian Unreason Through packing images into square texture and Simon 's answer I got to this link http://code.activestate.com/recipes/442299/ I did not check the recipe, but it seems to allow using non-square containers. Grembo I think what you

Union and struct packing problem

无人久伴 提交于 2019-11-30 14:35:15
I'm writing some software where each bit must be exact(it's for the CPU) so __packed is very important. typedef union{ uint32_t raw; struct{ unsigned int present:1; unsigned int rw:1; unsigned int user:1; unsigned int dirty:1; unsigned int free:7; unsigned int frame:20; } __packed; }__packed page_union_t; that is my structure and union. It does not work however: page_union_t p; //..... //This: p.frame=trg_page; p.user=user; p.rw=rw; p.present=present; //and this: p.raw=trg_page<<12 | user<<2 | rw<<1 | present; should create the same uint32. But they do not create the same thing. Is there

Packing rectangles for compact representation

只愿长相守 提交于 2019-11-30 05:03:55
问题 I am looking for pointers to the solution of the following problem: I have a set of rectangles, whose height is known and x-positions also and I want to pack them in the more compact form. With a little drawing (where all rectangles are of the same width, but the width may vary in real life), i would like, instead of. -r1- -r2-- -r3-- -r4- -r5-- something like. -r1- -r3-- -r2-- -r4- -r5-- All hints will be appreciated. I am not necessarily looking for "the" best solution. 回答1: Your problem is

Union and struct packing problem

风格不统一 提交于 2019-11-29 20:13:10
问题 I'm writing some software where each bit must be exact(it's for the CPU) so __packed is very important. typedef union{ uint32_t raw; struct{ unsigned int present:1; unsigned int rw:1; unsigned int user:1; unsigned int dirty:1; unsigned int free:7; unsigned int frame:20; } __packed; }__packed page_union_t; that is my structure and union. It does not work however: page_union_t p; //..... //This: p.frame=trg_page; p.user=user; p.rw=rw; p.present=present; //and this: p.raw=trg_page<<12 | user<<2

Why does git keep telling me it's “Auto packing the repository in background for optimum performance”?

廉价感情. 提交于 2019-11-29 20:05:38
Note : I don't think this is a duplicate of this question , which is talking about a non-background pack which hangs git with a subtly different error message . In one of my git repositories, each time I invoke (for example) git fetch , git prints: Auto packing the repository in background for optimum performance. See "git help gc" for manual housekeeping. It appears to print this every time if I do a git fetch repeatedly, even when there are no changes and nothing for git fetch to do. This doesn't make a lot of sense to me. It also seems to happen with other network operations, such as git

How many squares can be packed into a circle?

懵懂的女人 提交于 2019-11-29 15:11:50
问题 How many squares of size a × a can be packed into a circle of radius R ? I don't need a solution. I just need some kind of a starting idea. 回答1: I apologise for writing such a long answer. My approach is to start with a theoretical maximum and a guaranteed minimum. When you approach the problem, you can use these values to determine how good any algorithm you use is. If you can think of a better minimum then you can use that instead. We can define an upper limit for the problem by simply

packing algorithm in rtree in boost

*爱你&永不变心* 提交于 2019-11-29 09:30:16
Hi all I understand that if rtree is created with range values in boost it would use packing algorithm. I need an example of rtree using packing algorithm. Here is my code that uses quadratic algorithm using point = bg::model::point < int, 2, bg::cs::cartesian >; using pointI = std::pair<point, std::size_t>; vector<point> contourCenters // has some value bgi::rtree< pointI, bgi::quadratic<16> > rtree; vector< pointI > cloud; for (size_t i = 0; i < contourCenters.size(); ++i) { int x = contourCenters[i].get < 0 >(); int y = contourCenters[i].get < 1 >(); cout << "Contour Centers: (" << x << ","

Java Convert 4 bytes to int

半城伤御伤魂 提交于 2019-11-29 01:36:10
i was wondering if the solution for this documented here is still the solution or is there any other way getting an int from 4 bytes? thank you. EDIT: im getting the byte[] from sockets .read EDIT: int recvMsgSize = in.read(Data, 0, BufferSize); if recvMsgSize is -1 i know the connection has been dropped. how do i detect this when im using DataInputStream instead of InputStream? thanks. EDIT: apologies for being a yoyo regarding accepting the right answer. but after mihi's updated final response, it would appear that the method is solid and cuts down extended coding and in my opinion best

Given a target sum and a set of integers, find the closest subset of numbers that add to that target

自闭症网瘾萝莉.ら 提交于 2019-11-28 19:35:00
I have a set of integers M and a target sum k. I want to find the subset of M that when added together is the closest to k without going over. For example: M = {1, 3, 5, 5, 14} k = 12 answer = {1, 5, 5} because 1 + 5 + 5 = 11 and there is no way to make 12. I have the additional constraint that the subset can contain at most 4 elements. In my application, the size of |M| can be large (on the order of thousands of elements). If it is not possible to find the optimal answer in a reasonable time, I am interested in solutions that at least give a "good" answer. Right now I am solving this problem