Shopping at LEGO or Amazon?
Please use our links:
LEGO.com •
Amazon
As an Amazon Associate we earn from qualifying purchases.
Automated BrickLink cost minimization program available
I am a frequent user of BrickLink, and often after creating a Wanted list, I would find no one vendor with everything I wanted in stock. The resulting manual search for the least expensive mix of vendors to purchase from was time-consuming. Therefore, I wrote an automated tool to do this search for me which I'd be happy to share.
For a given Wanted list, my program downloads BrickLink pricing info for all desired pieces and does a search over all possible vendors to find the combination that fills the order at the least cost. It can also filter on New vs Used parts, specific or undefined color, US vs international sellers, and split partial quantities over multiple vendors if desired totals can be met.
My solution is a package of Matlab scripts which I can share with anyone who asks; just send me a message. The tool does require Matlab, but I'm probably not the only Matlab-using engineer in this demographic, and I'd welcome any effort to make this into a stand-alone executable. The example for parsing a Brick Link Price Guide page might be helpful to programmers on its own, and I'd also be interested in hearing about any other solutions that solve the same problem.

5
Shopping at LEGO.com or Amazon?
Please use our links: LEGO.com • Amazon
Recent discussions •
Categories •
Privacy Policy •
Brickset.com
Comments
Shipping costs (like "min shopping cost is $
Some m-files will run with only minor alteration in Scilab, the free Matlab-a-like alternative. Not sure if it supports web access though. Might be worth a look?
I would very much like to use the tool @atxdad wrote, but need it to run on free-ware.
I'll also share a couple anecdotes from development that illustrate the utility of the cost analysis. In preparing to make a $100+ order, the algorithm found me a solution that was 20% cheaper than the best solution I could find manually. I have also found examples where it is 40% cheaper to buy a set by pieces instead of as a whole. I think this is a tool buyers need because the calculations exceed human ability and the savings are potentially significant.
but for the buyer - it's a huge win.
I haven't tried the Matlab program yet, but I'm definitely interested.
Sounds like a great tool, so +1 to what @jocappy said ^
PS nice to see a big bricklinker on here @DadsAFOL.
If you can install software and click through a few buttons then you should be able to do the same. For those interested do a Google search for it, also get the Octave GUI (again google search). You'll need to download a zip utility www.7-zip.org to unpack Octave, its free too. Once this is installed you can launch the GUI executable and tell it where the Octave binary is located, this way you have a nice GUI to run from instead of just a command line (which can frighten those not familiar with command line stuff)
Please note running the scripts is not a simple executable file, there is some typing involved (>> run RUN_ALL.m ) and if you want to change things from the default you'll have to do some basic text editing on @atxdad's scripts.
Out of the box the current code creates plots, but after I disabled them my runtimes of ~10-20min for a 23 item part list that searched across all 1,2, and 3 vendor combinations for the lowest price.
-Optimizations to decrease run time by 25%
-Better compatibility with Matlab emulators
-Notes for non-US buyers
-Additional analysis tools that try to reduce run times by intelligently limiting the search space
Experience has shown that an exhaustive search for a least-cost solution can exceed practical run times when the number of vendors to consider is too large. (An NchooseK problem explodes.) In those cases, new analysis tools can be enabled that try to guide the user in pruning vendors from that search that would likely not be part of a final solution anyway. Doing so can potentially find a solution that would otherwise take too long to compute but without the mathematical certainty that it is the best solution.
Thanks for the comments so far, especially from those who have given it a try.
Except I'm not a programmer so will just have to wait :O)
Amazing you're getting 40% discount against some sets!!
One issue is shipping costs... Getting everything for slightly higher prices, but from far fewer sources, can actually be less expensive than ordering 3 parts here, 6 parts there, etc.
True, if the prices aren't even reasonable, that is a factor, but there is also the issue of placing 10 orders and keeping track of those, vs. placing 50 orders and trying to keep them all straight.
$300 to put together a set with just a few orders vs. $200 to try and put it together from dozens and dozens of orders, seems like a poor use of time.
Unfortunately I haven't a clue to what you guys are talking about with the tech speak, so I really hope this eventually can be made useable by the most software illiterate users like me! ;oP
There's a few smaller/medium builds I'd like to try but haven't bothered with because of the piecing it together aspect - so I think this would make things much easier.
I'm okay with paying a little more for pieces if I can get them from as few sellers as possible, but I realize other collectors have just the opposite view. There is no right way or wrong way - we're all free to choose our own way. The important thing is getting what we want. :oD
“error: urlread: curl: HTTP response code said error”
(you don't say! :D)
any clues?
Unfortunately MATLAB is horrible when it comes to creating executables or DLL's. Last time I had to do it you still needed to install a 200MB 'mini-MATLAB' and then depending on other things on your system you had about a 3in4 chance of it working properly. Eventually I gave up and just coded all the maths from scratch in C and dumped MATLAB once and for all. But I suspect that wouldn't be a trivial thing with this tool.
However, if it can be run through free versions of MATLAB-A-LIKES then that sounds like the best route for those without MATLAB. Maybe with some simple user guide to walk through the steps?
For my 30 lot/135 piece list, the 2 vendor price was $29.70. The 3 vendor solution is $15.23. Adding another vendor will probably add another $2-3 in shipping, so I'll still save around $10 but using 3 instead of 2 vendors.
Here's also what I've done to let me use the program in Canada against US/Canadian vendors:
1 - created a short script, getstores.m that went through all ~380k vendors in Bricklink and populated the vendor_locations.mat file with those that were Canadian or US
2 - modified the parsepriceguidestring.m
a) remove the check for '~' in the price
b) change the text 'US' to price 'CA' for the 'priceindstart' findnextstring call
Thanks for the great work atxdad!
cheers - mark
I've never programmed anything in matlab. Just wondering why you chose that for your language instead of something else. If this were a web app in PHP/Javascript, I could see more people using it.
Thanks!
Anyone care to port the (hopefully coming) desktop software to Mac? Pretty please?
I finally ended up pulling all my rare parts off my list onto a separate one, buying those items first, along with whatever else I needed to buy to meet vendor minimums, then removing those items as well from the main list, and running the tool with what was left. worked great - ended up finding a 3-vendor match for a 46 lots, 384 piece wanted list. there were 2 cheaper 4-vendor matches as well, but the difference wasn't enough to cover the extra shipping charges, so I went with the 3.
When considering a large order, the first step is to use BrickStore. Use the Edit/Price/Set to PriceGuide/Current Inventory Minimum feature to see the theoretical minimum cost for your wanted list. If this exceeds your budget or cost of a set bought whole, stop here. The tool won't help.
Two common problems to mitigate:
I.) No combination of vendors satisfies the wanted list requirements
II.) Computation time is too long
I. NO SOLUTION FOUND:
If the tool could not find a solution, the likely causes and remedies are:
1) The list of vendors to consider is too small - Make the wanted list less restrictive. Within BrickStore, change some parts' quality from NEW to USED (The algorithm treats 'used' to mean look for both.) or change some colors to N/A (don't care).
2) The maximum number of vendors to combine is too small - By default, the tool searches for combinations of 1, 2, or 3 vendors. Increase this maximum by setting maxvendorstouse=4 (or more) in find_minimum_cost.m.
3) A part on the wanted list is rare or desired in a quantity too large - If a part is sold by only a few vendors, one of them MUST have a slot in the final solution, reducing the flexibility of the tool to fill the remainder of the order. The same is true if few vendors have sufficient inventory of a part. Make a subset wanted list of only the rarest part(s); use the tool to find a solution for the subset and then again for the remainder of the wanted list. (see @dougts above)
II. LONG COMPUTATION TIME
The program's run time is dependent upon the number of vendors being considered. As a wanted list grows, the number of vendors selling any part on that wanted list also grows. Furthermore, every additional vendor to include in a solution (maxvendorstouse) increases run time by at least an order of magnitude. The following suggestions keep the vendor list constrained even when the number of wanted lots is high, and these can be tried without having to pull pricing data each time (skip parse_wanted_list_and_price_guide.m).
1) Apply the minimum quantity filter to prune vendors selling only a few of an item that is needed in large quantities. See the 'minimumqty' vector in merge_price_guide_data.m.
2) Apply logic intended to remove vendors with few desired lots available. Enable by setting 'usevendorpruninglogic' flag in merge_price_guide_data.m. Accept the recommended defaults for pruning thresholds to reduce vendor list by ~50%. Safeties prevent the pruning of vendors selling rare parts or a high percentage of total desired parts.
If the default pruning still results in excessively large vendor lists (>300) and run times, aggressively prune the vendor list to <100 by manually entering pruning thresholds, overriding the defaults. Plots will guide threshold definition. Run find_minimum_cost.m to see if ANY solution can be found in a reasonable time, even if not necessarily the least cost. Iteratively repeat with a larger vendor list (less pruning), until 1) a solution is found at a satisfactory price or 2) run times lengthen to intolerable levels.
In conclusion, I think casual use of this tool will not require the level of human oversight described above, so one shouldn't be intimidated by these instructions. However, there is clearly a population of motivated buyers who want to push its limits. I hope this helps!
It would be so awesome if someone programmed something like this with a nice GUI and as a stand alone program. I would pay $$$ for it!,
I was trying to get work this manually with two wanted lists last night and even with the small 9 lot list it was a PITA. I just gave up on the 180 lot list. This and the variable shipping costs and minimum order limits are why I don't buy from BL.
Now if Rebrickable.com could just embed this technology and BL started paying referrals to off set their costs the problem for most people would be solved.
- The cost analysis can now show detail for the 'Top 10' least expensive solutions instead of just the single best solution
- Total cost/lots per vendor is shown to quickly know if minimum purchase/maximum lot terms are met
- Rare parts that may be preventing a solution are identified
Often there are multiple solutions within a few cents of each other, and I would consider all viable options. Now the user will have enough information to screen roughly equivalent solutions for all of the following before making a purchase decision:
- Minimum purchase/maximum lot requirements
- Shipping costs
- Feedback ratings
- Country of origin
I'm next considering ways to ease turning a hypothetical solution into a real purchase, maybe by generating store-specific wanted lists, etc. Ideas are welcome, and thanks to those who are giving it a try.
* Automated creation of vendor-specific Wanted Lists that can be uploaded into BrickLink
* Ability to blacklist/whitelist specific vendors from the search
The latter may seem trivial but helpful in exluding vendors that waste run time with huge inventories of available lots at unreasonably elevated prices. However, the ability to forcibly INCLUDE vendors in the search space is vital to finding solutions for massive parts lists in a reasonable time.
Specifically, a large wanted list can be broken into subsets which search relatively quickly. All those intermediate solution vendors are then forced (whitelisted) into a reduced vendor search space for the original wanted list. At least one solution is guaranteed to be found for the original list, and possibly one at less cost than the sum of the subsets, within a maximum run time you can control by pruning the vendor search space.
Thanks to everyone who continues to send suggestions!
What is the logic in sellers operating like that?
Let me know if anyone would be willing.
Thanks, Brian