1 / 14

number partitioning

number partitioning. Given a bag of numbers, can you partition this into 2 bags such that the sum of the integers in each bag is equal?. Recently featured in the Crystal Maze! (Thanks Zoe!). Try it!. Can you think of a 1st test to carry out to determine if there is no partition?.

kerry
Download Presentation

number partitioning

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. number partitioning

  2. Given a bag of numbers, can you partition this into 2 bags such that the sum of the integers in each bag is equal? Recently featured in the Crystal Maze! (Thanks Zoe!)

  3. Try it!

  4. Can you think of a 1st test to carry out to determine if there is no partition?

  5. Given a bag of numbers, can you partition this into 2 bags such that the sum of the integers in each bag is equal? Garey & Johnson “Computers and Intractability” [SP12] PARTITION INSTANCE: Finite set A and a size s(a)  Z+ for each a  A QUESTION: Is there a subset A’  A such that aA’ s(a)  aA-A’ s(a)

  6. How complex?

  7. Who cares? Imagine you have 2 machines on the shop floor You have n activities, of varying durations Place the activities on the machines to minimise makespan

  8. Why just 2-partition? Why not m-way partitioning? Is there an optimisation problem?

  9. A number of constraint encoding chocoExamples/numPart.cl

  10. 10 4 5 3 2 1 8 7 3 5 9

  11. [numPart1(fname:string) : Problem -> let f := fopen(fname,"r"), n := read(f), p := makeProblem(fname,n + n), A := list<IntVar>(), B := list<IntVar>(), sum := 0 in (for i in (1 .. n) let m := read(f), mA := makeIntVar(p,"A" /+ string!(m),list(0,m)), mB := makeIntVar(p,"B" /+ string!(m),list(0,m)) in (add(A,mA), add(B,mB), post(p,mA !== mB), sum := sum + m), fclose(f), post(p,sumVars(A) == sumVars(B)), p)] // // is this okay? //

  12. [numPart2(fname:string) : Problem -> let f := fopen(fname,"r"), n := read(f), p := makeProblem(fname,n + n), A := list<IntVar>(), B := list<IntVar>(), sum := 0 in (for i in (1 .. n) let m := read(f), mA := makeIntVar(p,"A" /+ string!(m),list(0,m)), mB := makeIntVar(p,"B" /+ string!(m),list(0,m)) in (add(A,mA), add(B,mB), post(p,mA !== mB), sum := sum + m), fclose(f), post(p,sumVars(A) == sum / 2), post(p,sumVars(B) == sum / 2), p)] // // is this better than numPart1? If so, why? //

  13. [numPartMin(fname:string) : tuple -> let f := fopen(fname,"r"), n := read(f), p := makeProblem(fname,n + n + 3), A := list<IntVar>(), B := list<IntVar>(), sum := 0 in (for i in (1 .. n) let m := read(f), mA := makeIntVar(p,"A" /+ string!(m),list(0,m)), mB := makeIntVar(p,"B" /+ string!(m),list(0,m)) in (add(A,mA), add(B,mB), post(p,mA !== mB), sum := sum + m), fclose(f), let sumA := makeIntVar(p,"sumA",0,sum), sumB := makeIntVar(p,"sumB",0,sum), diff := makeIntVar(p,"diff",0,sum) in (post(p,sumVars(A) == sumA), post(p,sumVars(B) == sumB), post(p,ifOnlyIf(sumA >= sumB,diff == sumA - sumB)), post(p,ifOnlyIf(sumB > sumA,diff == sumB - sumA)), tuple(p,diff)))] // // minimise the difference between the two set // // t:tuple := numPartMin("np10") // minimize(t[1],t[2],true) //

More Related