Closed gabidi closed 7 years ago
Hi, Sorry for the late answer, for some reason I did not see your issue earlier.
I have a few questions to understand the problem: What does the interval [0, 20] represent? The maximum number of c2-3 units that can be shipped? or the maximum number of c2-3 units that be added to another product? Therefore is it possible to ship 40 c2-3 units by attaching them to two different products?
Hey, Thank you so much for taking the time to reply. It is appreciated !
Variables represent boxes of products , and so the interval represents how many types of a product this box can handle (ex: c2-3 , can accept 0-20 addon items). Constraints represent the products that need to be shipped. (ex: we have to ship 20 addon items for this order)
So for this example we would have 20 addon items that can be packaged in n number of boxes of type c2-3 and c3-4 in which ever way minimizes the cost.
Hope that makes more sense and would love to get your input. Thank you so much for your time :)
Hi again,
So if I understand correctly, adding one unit of c2-3 allow for up to 20 more addon items to the shipment. I do not see any price nor any variables for addon items, so I suppose they do not cost anything (is it normal?).
Would the following formulation fit your problem:
{
optimize: 'price',
opType: 'min',
constraints: {
solo: { equal: 2 },
combo: { equal: 2 },
ok: { equal: 3 },
addon: { min: 20 }
},
variables: {
'c1-1': { solo: 1, price: 100, time: 3 },
'c2-3': { addon: 20, price: 10, time: 2 },
'c3-4': { combo: 1, addon: 20, ok: 1, price: 20, time: 3 },
'c3-5': { combo: 1, ok: 1, price: 20, time: 3 },
'c3-6': { ok: 1, price: 20, time: 3 },
'c4-7': { solo: 1, addon: 5, price: 15, time: 3 }
ints: {
'c1-1': 1,
'c2-3': 1,
'c3-4': 1,
'c3-5': 1,
'c3-6': 1,
'c4-7': 1
}
}
I simplified "solo", "combo" and "ok" constraints to equality constraints for simplification.
Hey thanks for the quick reply,
All constraints represent the actual number of items that HAVE to be shipped (So addon : { equal: 20}) The variables represent the different box we can ship these items in.
So for your representation :
{
optimize: 'price',
opType: 'min',
constraints: {
solo: { equal: 2 },
combo: { equal: 2 },
ok: { equal: 3 },
addon: { min: 20 }
},
variables: {
'c1-1': { solo: 1, price: 100, time: 3 },
'c2-3': { addon: 20, price: 10, time: 2 },
'c3-4': { combo: 1, addon: 20, ok: 1, price: 20, time: 3 },
'c3-5': { combo: 1, ok: 1, price: 20, time: 3 },
'c3-6': { ok: 1, price: 20, time: 3 },
'c4-7': { solo: 1, addon: 5, price: 15, time: 3 }
ints: {
'c1-1': 1,
'c2-3': 1,
'c3-4': 1,
'c3-5': 1,
'c3-6': 1,
'c4-7': 1
}
}
we can have a solution like (Ie we can package the order into boxes) :
{ 'c1-1' : 1 ,
'c2-3': 1,
'c3-5': 2 ,
'c3-6' : 1
}
This is just one solution that while is not optimal (min price) is satisfactory to have all the items (constraints) consumed (shipped) by the box (variables).
Now the issue comes with Add on items in boxes dont have to be fixed, so when i say something like
'c3-4': { combo: 1, addon: { min: 0, max:20 }, ok: 1, price: 20, time: 3 }
the equivalent without using the min and max notation would be to expand the above box into individual representations as such: 'c3-4-1': { combo: 1, addon: 1, ok: 1, price: 20, time: 3 } 'c3-4-2': { combo: 1, addon: 2, ok: 1, price: 20, time: 3 } 'c3-4-3': { combo: 1, addon: 3, ok: 1, price: 20, time: 3 } 'c3-4-4': { combo: 1, addon: 4, ok: 1, price: 20, time: 3 } .... etc.. 'c3-4-20': { combo: 1, addon: 20, ok: 1, price: 20, time: 3 }
and then solve that system.
Of course this gets even more complicated if you have a box that looks like: 'c3-4': { combo: 1, addon: { min: 0, max:20 }, ok: { min : 1 , max: 3}, price: 20, time: 3 }
You would have to expand that rule to be 20*3 to cover all cases.
Hope that helps you understand the issue better and again thank you so much for your thoughts !
Hey, Sorry I could not get back to you more quickly.
I think I understand your problem and I think that the solution I provided solves it, can you try to solve it and see if it gives satisfactory result:
{
optimize: 'price',
opType: 'min',
constraints: {
solo: { equal: 2 },
combo: { equal: 2 },
ok: { equal: 3 },
addon: { min: 20 }
},
variables: {
'c1-1': { solo: 1, price: 100, time: 3 },
'c2-3': { addon: 20, price: 10, time: 2 },
'c3-4': { combo: 1, addon: 20, ok: 1, price: 20, time: 3 },
'c3-5': { combo: 1, ok: 1, price: 20, time: 3 },
'c3-6': { ok: 1, price: 20, time: 3 },
'c4-7': { solo: 1, addon: 5, price: 15, time: 3 }
ints: {
'c1-1': 1,
'c2-3': 1,
'c3-4': 1,
'c3-5': 1,
'c3-6': 1,
'c4-7': 1
}
}
You have to compute by yourself to which box to attribute addons (which should be trivial) but you are guaranteed that you will have the necessary amount of space to ship at least 20 addons.
@gabidi are you good if I close this out?
@JWally Yep , thank you very much.
Hey ! Thank you so much for making this awesome library :)
I have a quick question, is it possible to set min,max conditions in your variables? (see example code below)
Example: You have 4 types of products to ship (solo, combo, addon, ok) and you have different types of shipments (c1-1,c2-3, etc..) that fit different combinations of products and have different costs and time for delivery. You need to ship ALL products but you can ship them in different ways. Some products can be shipped with others, some not and some products can ONLY be shipped with other products (addon).
We need to solve for integer values for the best combination of boxes to use while minimizing cost .
Example code below:
is it possible to represent the fact that 'addon' products can be easily moved between any box that has capacity for them by adding :
in a variable constraint ? If not is there a way to simulate it ?
Thanks again !