求一个最优的算法
条件格式:
{nm:'组合1',p:3,l:[{id:1,n:3},{id:2,n:2}]}
组合1,价格3元,限制条件为: id1*3+id2*2=3
类似的条件可能有若干
{nm:'组合2',p:5,l:[{id:1,n:1},{id:3,n:1}]}
等等
将所选的价格列表
[{id:1,n:2},{id:2,n:3},{id:3,n:5}]
现在每个价格只能参与一次组合,但是必须是最优惠的
具体数据如下:
//套票总规则
var pricerule= [{ "p": 3.0, "i": 181030, "n": 2, "nm": "3(2*2)", "ol": 0, "s": 1, "l": [{ "i": 690169, "n": 2 }] }, { "p": 5.0, "i": 181031, "n": 2, "nm": "5(2*1+4*1)", "ol": 0, "s": 1, "l": [{ "i": 690169, "n": 1 }, { "i": 690170, "n": 1 }] }, { "p": 11.0, "i": 181036, "n": 3, "nm": "11(4*3)", "ol": 0, "s": 1, "l": [{ "i": 690170, "n": 3 }] }];
{p:价格,i:编号,n:数量,nm:名称,l:[{i:价格类ID,n:需要的数量}]}
//已选商品数据
var products= [{ "i": "452", "pid": 690169, "p": 2, "rr": "23", "rc": "3", "tid": 0, "color": "F91616", "pos": { "x": 529, "y": 289 } }, { "i": "476", "pid": 690169, "p": 2, "rr": "24", "rc": "3", "tid": 0, "color": "F91616", "pos": { "x": 552, "y": 289 } }, { "i": "477", "pid": 690169, "p": 2, "rr": "24", "rc": "4", "tid": 0, "color": "F91616", "pos": { "x": 552, "y": 312 } }, { "i": "453", "pid": 690169, "p": 2, "rr": "23", "rc": "4", "tid": 0, "color": "F91616", "pos": { "x": 529, "y": 312 } }, { "i": "469", "pid": 690171, "p": 0.1, "rr": "23", "rc": "21", "tid": 0, "color": "EEB31B", "pos": { "x": 529, "y": 703 } }, { "i": "493", "pid": 690171, "p": 0.1, "rr": "24", "rc": "21", "tid": 0, "color": "EEB31B", "pos": { "x": 552, "y": 703 } }, { "i": "500", "pid": 690170, "p": 1.1, "rr": "24", "rc": "21", "tid": 0, "color": "EEB31B", "pos": { "x": 552, "y": 703 } }, { "i": "500", "pid": 690170, "p": 1.1, "rr": "24", "rc": "21", "tid": 0, "color": "EEB31B", "pos": { "x": 552, "y": 703 } }, { "i": "500", "pid": 690170, "p": 1.1, "rr": "24", "rc": "21", "tid": 0, "color": "EEB31B", "pos": { "x": 552, "y": 703 } }, { "i": "500", "pid": 690170, "p": 1.1, "rr": "24", "rc": "21", "tid": 0, "color": "EEB31B", "pos": { "x": 552, "y": 703 } }];
{i:商品编号,pid:价格类ID,p:商品价格},其他数据忽略