packing

Algorithm to organise rectangles in the fixed rectangular container

孤街浪徒 提交于 2020-01-01 03:28:06
问题 My problem is pretty similar to 2D Knapsack problem, or cutting stock with one exception... the rectangles that fit into the container can be resized and cropped. No rotation is allowed though. The challenge is to make as little crops as possible and fill entire container (no gaps whatsoever). Has anyone encountered an algorithm that would do something similar. Any links, pseudo code much appreciated. Kept the question generic, but I'd like to apply it to organise photos on a fixed size page.

Why doesn't C++ make the structure tighter?

半世苍凉 提交于 2019-12-28 02:49:11
问题 For example, I have a class , class naive { public: char a; long long b; char c; int d; }; and according to my testing program, a to d are built one after another, like a------- bbbbbbbb c---dddd - means unused. Why does not C++ make it tighter, like ac--dddd bbbbbbbb 回答1: Class and struct members are required by the standard to be stored in memory in the same order in which they are declared. So in your example, it wouldn't be possible for d to appear before b . Also, most architectures

GCC: Alignment settings with __attribute__ and #pragma

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 09:16:09
问题 How can I define #pragma pack(2) as a structure attribute? I've read here that __attribute__((packed,aligned(4))) is roughly equivalent to #pragma pack(4) . However, if I try to use this (at least with 2 instead of 4), I get different results. Example: #include <stdio.h> #pragma pack(push, 2) struct test1 { char a; int b; short c; short d; }; struct test1 t1; #pragma pack(pop) struct test2 { char a; int b; short c; short d; } __attribute__((packed,aligned(2))); struct test2 t2; #define test(s

Maximum packing of rectangles in a circle

吃可爱长大的小学妹 提交于 2019-12-21 09:06:15
问题 I work at a nanotech lab where I do silicon wafer dicing. (The wafer saw cuts only parallel lines) We are, of course, trying to maximize the yield of the die we cut. All the of die will be equal size, either rectangular or square, and the die are all cut from a circular wafer. Essentially, I am trying to pack maximum rectangles into a circle. I have only a pretty basic understanding of MATLAB and an intermediate understanding of calculus. Is there any (relatively) simple way to do this, or am

Bin packing bruteforce method

放肆的年华 提交于 2019-12-21 02:46:15
问题 I need to make program that solves bin packing problem, but I already made first fit and greedy algorithms, but my lecturer says in some cases it won't find the minimal solution to the problem. So i decided to try bruteforce, but I have no clue how it should check all possible solutions. So yea.. can someone explain to me or give pseudo-code or something. I would appreciate a lot. 回答1: Note that bin-packing is an NP-hard problem, basically meaning it will take excessively long to run brute

Why does a struct consisting of a char, short, and char (in that order), when compiled in C++ with 4-byte packing enabled, come to a 6-byte struct?

喜夏-厌秋 提交于 2019-12-19 09:10:34
问题 I thought I understood how C/C++ handled struct member alignment. But I'm getting strange results for a particular arrangement in Visual Studio 2008 and 2010. Specifically, I'm finding that a struct consisting of a char, short, and char is compiled into a 6-byte struct, even with 4- or 8-byte packing enabled. I am at a loss as to why this would be. I can understand a 4-byte struct. I could perhaps understand an 8-byte struct. But I would think that a 6-byte struct would be impossible when 4

How to make class in C#, that can be cast to DateTime?

时间秒杀一切 提交于 2019-12-19 05:13:36
问题 How can I make class, that can be cast to DateTime. But I need to cast my class, when it packed. For example: object date1 = new MyDateTime(); DateTime date2 = (DateTime)date1; I need directly this working example. I know how to do it, but my way will work without packing. I'm not sure is there way to do it. Please, help. PS. I need cast directly object to DateTime. So, MyDateTime have to be packed before. Explicit works well, but it doesn't help if you have packed object. And it have to cast

Fitting rectangles together in optimal fashion

扶醉桌前 提交于 2019-12-18 21:21:14
问题 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 回答1: Through packing images into square texture and Simon's answer I got to this link http://code.activestate.com/recipes/442299/ I

Java Convert 4 bytes to int

陌路散爱 提交于 2019-12-18 03:32:16
问题 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

fitting n variable height images into 3 (similar length) column layout

可紊 提交于 2019-12-17 07:26:28
问题 I'm looking to make a 3-column layout similar to that of piccsy.com. Given a number of images of the same width but varying height, what is a algorithm to order them so that the difference in column lengths is minimal? Ideally in Python or JavaScript... Thanks a lot for your help in advance! Martin 回答1: How many images? If you limit the maximum page size, and have a value for the minimum picture height, you can calculate the maximum number of images per page. You would need this when