Thuật toán để giảm thiểu diện tích bề mặt, khối lượng đã cho


22

Hãy xem xét các nhiệm vụ thuật toán sau:

Đầu vào: một số nguyên dương , cùng với hệ số nguyên tố của nó Tìm: các số nguyên dương thu nhỏ , tuân theo giới hạnn
x,y,zxy+yz+xzxyz=n

Sự phức tạp của vấn đề này là gì? Có một thuật toán đa thức thời gian? Có khó NP không?


Vấn đề này về cơ bản hỏi: trong số tất cả các vật rắn hình chữ nhật có thể tích là và kích thước của chúng là tất cả các số nguyên, cái nào có diện tích bề mặt nhỏ nhất?n

Vấn đề này được Dan Meyer đặt ra, dưới tiêu đề Vấn đề toán học mà 1.000 giáo viên toán học không thể giải quyết . Cho đến nay, không có giáo viên toán nào mà anh làm việc cùng đã tìm thấy một thuật toán hợp lý cho vấn đề này. Trong bối cảnh của ông, định nghĩa "hợp lý" là một chút không chính xác, nhưng là các nhà khoa học máy tính, chúng ta có thể hỏi một câu hỏi chính xác hơn về sự phức tạp của vấn đề này.

Cách tiếp cận rõ ràng là liệt kê tất cả các khả năng cho , nhưng điều đó cần có thời gian theo cấp số nhân. Các nhà bình luận tại blog của Dan Meyer đã đề xuất nhiều thuật toán ứng viên hiệu quả mà không may tất cả hóa ra là không chính xác. Martin Strauss cho rằng vấn đề này có vẻ gợi nhớ một cách mơ hồ về phân vùng 3 , nhưng tôi không thể thấy sự giảm bớt.x,y,z


Tôi cũng xin làm sáng tỏ một số quan niệm sai lầm mà tôi đã thấy trong các bình luận / câu trả lời:

  • Bạn không thể giảm từ 3 phân vùng bằng cách thay thế mỗi số bằng sức mạnh của nó , vì các hàm mục tiêu của hai vấn đề là khác nhau. Giảm rõ ràng đơn giản là không hoạt động.q2q

  • Không đúng khi giải pháp tối ưu liên quan đến việc chọn một trong các là ước số gần nhất của thành . Tôi thấy nhiều người cho rằng đây là trường hợp, nhưng thực tế, điều đó không đúng. Điều này đã được chứng minh trên bài đăng trên blog của Dan Meyer. Chẳng hạn, hãy xem xét ; và 4 chia 68, vì vậy bạn có thể nghĩ rằng ít nhất một trong số phải là 4; tuy nhiên, điều đó không đúng Giải pháp tối ưu là , , . Một ví dụ khác là , , nhưng giải pháp tối ưu làx,y,znn3n=686834x,y,zx=2y=2z=17n=22222236x=37, y=3, z=2. (It might be true that for all n, the optimal solution involves making at least one of x,y,z be equal to either the smallest divisor of n larger than n3 or the largest divisor of n smaller than n3 -- I don't have a counterexample right now -- but if you think this statement is true, it would need proof. You absolutely cannot assume it is true.)

  • "Make x,y,z be the same size" does not appear to necessarily yield the optimal answer in all cases; see Dan Meyer's blog post for counterexamples. Or, at least, for some reasonable interpretations of the phrase "make them roughly the same size", there are counterexamples showing that this strategy is not in fact optimal. If you want to try some strategy of that sort, make sure that you state the claim precisely and then provide a careful mathematical proof.

  • A running time of O(n3) is not polynomial. For this problem to be in P, the running time must be a polynomial in the length of the input. The length of the input is something like lgn, not n. The obvious brute-force algorithm can be made to run in O(n3) or O(n2) time, but that is exponential in lgn and thus counts as an exponential-time algorithm. Thus that is not helpful.


1
Interesting. My naive approach would be "make x,y,z roughly the same size", generalizing the idea that the cube is the rectangular solid with the smallest surface area for a given volume. Would that work? And if so: I don't see how to do that efficiently, but is there a reduction that's easier to attain, maybe?
G. Bach

2
A reduction is going to be a nightmare since you need a way to generate suitable prime numbers. The best you could hope for is a randomized reduction, using something like Dirichlet's Theorem to generate suitable primes but even that seems unlikely.
Tom van der Zanden

1
@G.Bach, I think that blog article considers a bunch of heuristics of that vein (e.g., start with each of x,y,z to be the nearest integer to n3 and then adjust them a tiny bit), and shows explicit counterexamples for each. But maybe you have an algorithm that they haven't considered?
D.W.

3
oeis.org/A075777 seems to claim an algorithm, but it appears to be incorect (n=1332 generates 9,4,37 instead of 6,6,37 for example)
Scott Farrar

1
Here's an observation that may be useful. Given x, the optimal y,z do in fact satisfy the "naive dream": they must be the pair of factors of n/x closest to n/x. (This is easy to prove.) At an optimal solution x,y,z, this condition must hold for all three variables simultaneously: x,y are the pair corresponding to z, etc. One implication: given z, there is only one possible pair x,y with which it can be optimal. Unfortunately, (1) this condition does not uniquely identify the optimal triple; (2) I don't see how to find the corresponding pair fast.
usul

Câu trả lời:


1

Here is a modified version of a "choose divisor near cube root" algorithm. It still must brute force many cases, so I'm not sure how much of a real improvement it is speed wise over the enumeration of all cases. However, I submitted it as a correction to the algorithm on OEIS (that which generated incorrect results) because I believe it should be accurate at least.

Here is the algorithm to find (s1,s2,s3) and surface area of a rectangular prism given its volume n:

  1. Given n, find the cube root.
  2. Set an initial value integer s1 at the ceiling of that cube root.
  3. Test to see if s1 is a divisor of n, and if not, reduce s1 by 1.
  4. If a divisor s1 is found, set an initial s2 to be the ceiling of the square root of (n/s1).
  5. Then test to see if s2 is a divisor of n/s1, and if not, reduce s2 by 1.
  6. When a divisor s2 is found, s3 then is set to n/(s1*s2).
  7. The current surface area is calculated by 2*(s1*s2 + s1*s3 + s2*s3).
  8. The current SA is compared against the current minimum. If its the first surface area calculated, it is stored as minSA. After the first, we test to see if the current SA is smaller than minSA, and if so, store it in minSA.

This algorithm enumerates some of the triples (s1,s2,s3) but needs only to test the divisors under the cube root. (Since not all three divisors can be above the cube root). In a similar fashion, s2 needs only to test divisors of n/s1 under the square root of n/s1, since not both divisors can be above the square root)

A note on step 3: if the cube root is a divisor then n is a cube and we can stop there with minimal surface area 6*s1^2 from the box (s1,s1,s1).

Python:

import math
def minSArectprism(n):
    s1_0 = int(math.ceil(n ** (1 / 3.0))) 
    minSA=-1
    s1 = s1_0
    while s1>=1:
        while n % s1 > 0:  
            s1 = s1 - 1
        s1quot = int(n/s1) 
        s2_0 = int(math.ceil(math.sqrt(n/s1)))
        s2 = s2_0
        while s2>=1:
            while s1quot % s2 > 0:
                s2 = s2 - 1
            s3 = int(n / (s1 * s2))  
            SA = 2*(s1*s2 + s1*s3 + s2*s3)  
            if minSA==-1:
                minSA=SA
            else:
                if SA<minSA:
                    minSA=SA
            s2 = s2 - 1
        s1 = s1 - 1    
    return minSA

Your algorithm takes exponential time. Each loop examines about n3 possible candidates, so the running time is O(n32)=O(n2/3), which is exponential, not polynomial time. Thus, this algorithm doesn't answer the question. (I already mentioned an exponential-time algorithm in the question.)
D.W.

Hmm, y is not confined under the cube root of n, for example, n=1332, we will eventually test s1=2, meaning s2 will be under the square root of 1332/2 ~= 26. Indeed (2,18,37) is tested with y and z above the cube root.
Scott Farrar

@ScottFarrar, yes, I know. I did not include all the gory details of the complexity analysis; there wasn't space in a single comment. If you do include the gory details, I think you'll find that you get the running time I quoted. You can either trust me :-), or read our reference question to learn more about those gory details. In any case, even if you removed the inner loop, the outer loop still does Θ(n1/3) iterations, so the running time of your algorithm is at least Ω(n1/3) -- i.e., it is certainly exponential.
D.W.

0

The problem would of course be related to factoring complexity if prime decompositions were not given. Given the factors, and taking logs of all the prime factors, this problem appears to be about the same as minimizing the deviation-from-mean of k partition sums (exercise, maybe either analytically or experimentally, find how closely this intuitive approximation of the problem holds).

Here this is the 3-way case (partition sums are log(x),log(y),log(z)). the 2-way case has been extensively studied and is NP hard (from 1st ref). (This 2-way case is not quite the same as the known NP-complete 2-way Partition problem where partition sums are equal. Note equal partition sums implies 0 deviation in partition sums and vice versa.) The 2nd ref studies 3-way and n-way partitioning, partly empirically, where there is not as much study as the 2-way case.


This answer is not helpful and does not answer the question. 1. I am looking for proofs or evidence, not speculation. There is no evidence that minimizing deviation yields an optimal solution. Even if that were true, it wouldn't answer the question: it would not tell us the complexity of minimizing the deviation. 2. The first reference is about 2-partition. Pointing me to a reference on 2-partition is not helpful. I already explained in the question why my problem is not just 3-partition (or 2-partition). A paper on a variant of a problem that I didn't ask about isn't helpful.
D.W.

Counterexample to the claim that you should minimize the absolute deviation from the mean: n=68. Then 1,4,17 yields an absolute deviation of 2.85342, which is the lowest possible absolute deviation. However 2,2,17 is the correct (optimal) solution, and has smaller surface area. [By absolute deviation from the mean, I specifically mean |log(x)μ|+|log(y)μ|+|log(z)μ| (where μ=(log(x)+log(y)+log(z))/3).]
D.W.

ok! there was never any claim this algorithm was correct, it was based on inspection of some examples & others suggestions in comments. this is only a single counterexample (you indicated the minimizing deviation method is flawed in the revised post). the question of "how often" this algorithm gives a correct solution is interesting because it could give some clues to a correct optimization metric. conjecture this algorithm "often" gives the correct answer. the 2-way ref is to show a deviation version of the problem which is different than the typical exact version on wikipedia etc
vzn

see also Lakatos Proofs and refutations
vzn

0

Edit

Here’s an informal argument for why a fast algorithm is unlikely to exist. That sentence hasn't changed, but I’ve taken out what used to be here because it was structured too much like the formal proof in the next section and the discussion was getting sidetracked onto its bugs, some of which I noticed myself and one of which D.W. kindly pointed out to me. Let me instead try to express the intuition behind it.

The clever approaches to this problem seem to be focusing on finding ways to partition the prime factors of N into three lists and quickly prune most of the combinations without needing to check them. So suppose this approach works, that is, it gives you a P-time algorithm for finding the optimal box.

What happens when we translate the same steps into a different algebra, such as addition and subtraction instead of multiplication and division? We know (see lemma below) that our algorithm will find a 3-partition whose products are equal, if one exists, or else determine that no such 3-partition exists. So, if we could translate the same techniques into the additive group, we could find a 3-partition whose sums are equal, or determine that no such partition exists. In other words, we could solve 3-partition in polynomial time. That’s not very plausible.

So, why might such an algorithm work for multiplication and fail for addition? One possible reason is that every integer has a unique prime factorization under multiplication, but is cyclic under addition. Another is that multiplication forms a ring with addition, so you have another set of operations you can use. Another is that you would have to generalize the algorithm to work for non-primes, and it might depend on their primality. The one D.W. pointed out is that the specific method of translation might exponentially increase the size of your inputs. And maybe P = NP after all.

But if those are the loopholes that let a fast algorithm work, I think it’s still useful to know, because it suggests where we should focus our efforts. We should be looking for something that would break if we tried to apply it to a NP-complete problem. An approach that would generalize to other algebras is probably barking up the wrong tree. I suspect, though, that multiplication is not really different enough for that to work, but that’s just a hunch.

Lemma

Let m=N3. For any solution (am,bm,mab), where a and b are positive, the weight of the solution is (ab+1a+1b)m2 and is minimized when a=b=1.

Proof: We see immediately from the restriction xyz=N that any arbitrary solution has this form.

Its weight is (am)(bm)+(am)(mab)+(bm)(mab)=abm2+m2b+m2a=(ab+1a+1b)m2.

Let f(a,b)=ab+1a+1b. To minimize this function, we take the partial derivatives δfδa=b1a2 and δfδb=a1b2. The critical point where these partial derivatives are zero comes where a=b2,b=a2, and therefore, since a and b must be real numbers greater than 0, a=b=1. We see from the matrix of second-order partial derivatives that this is a global minimum.

My immediate motivation to prove this was to fill in a hand wave in my proof above that, if a perfect-cube solution exists, it is optimal. However, this formula could be useful for pruning the search tree.

Assorted Thoughts

I don’t see any obvious symmetry except the interchangeability of x, y and z, which only gives us at best a constant factor of 6. We do have some speedups for the 2-partition that basically say we’d want both terms to be as close to each other as possible, but I don’t immediately see an application to this problem.

Off the top of my head, simply taking the log of all the numbers immediately reduces this to a classic 3-partition problem using addition, or equivalently, taking some number to the power of the numbers in any 3-partition addition problem turns it into a multiplication problem such as this. That implies this problem should not be any easier. We do have here the prime factorization, whereas that factorization would not be prime, but does that help us?

Graphically, the surface xyz = 0 would look like the union of the xy-, yz- and xz-planes, and for any positive n, the equation would look like y = n/xz, so each slice along a coordinate plane would be a hyperbola. We can generally say that the quantity we’re trying to minimize is lowest at the origin and grows most rapidly along the line where x = y = z. If we can search only along this manifold, we might be able to reduce to a two-dimensional problem.


If x+y+z=n, 2^n=2^(x+y+z)=2^x*2^y*2^z, which is an instance of this problem minus the restriction that the inputs are a prime decomposition of the product. They would instead all be powers of two.
Davislor

It’s true that the weight to minimize will be different, but if x=y=z in the original problem, won’t x'y'+x'z'+y'z' be minimized in the corresponding problem where each w is replaced by w'=2^w, meaning that if a solution to the original problem exists, the reduction would find it? We might get a spurious solution from the transformed problem, but we can detect that in linear time when converting back by verifying the sums.
Davislor

as above comment by GBach suggests, maximizing xy+yz+xz subject to xyz=n likely happens when x,y,z are "close together" or have low deviation (from average). this is not necessarily the same as "close to n3". the numerical examples given by Meyer on his page appear to fit this pattern.
vzn

@vzn: We’re trying to minimize surface area, not maximize it. If the 3-partition problem has a solution, that translates into a modified box-dimension problem where the solution is a perfect cube. A hypothetical poly-time algorithm would find the factors of the sides of that cube, and we could then translate it back into the original domain, while checking for spurious solutions, in linear time. That suggests an algorithm for a slightly-relaxed problem could serve as an oracle for a hard problem, making it unlikely a better-than-exponential algorithm exists.
Davislor

? am not disagreeing with you. arent we saying the same thing? plz drop by Computer Science Chat to untangle/ sort this out further. also cant follow @D.W.s claim that the logarithmic transformation doesnt work, can you? am using some of your (seemingly on-target) analysis as basis for my own answer.
vzn
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.