Code Monkey home page Code Monkey logo

bakery's Introduction

Bakery

This application loads in a customer's order and determines the packs of baked goods that should be supplied to fulfill the order.

When multiple combinations of packs can fulfill the order, the algorithm preferentially selects those with a larger quantity. This minimises the number of packs that need to be shipped.

This is a variation of the Knapsack Problem. In this case, the weights are the quantities in each pack and the total weight is set as the ordered quantity. Values aren't specified but we know that packs with larger quantities are preferred, thus these have a higher value/weight ratio.

Environments

This project was tested on Ubuntu 16.04 and Mac OS X.

System Dependencies

This application requires Ruby 2.4.1

Check your ruby version by running:

$ ruby -v

It is recommended to use a Ruby version manager such as RVM for managing Ruby versions. For information on RVM visit: https://rvm.io/rvm/install

$ rvm install 2.4.1

If already installed, you can switch versions using:

$ rvm use 2.4.1

Otherwise, to install Ruby visit: http://rubyinstaller.org/.

Installation

Clone the repository:

$ git clone https://github.com/clarkbab/bakery.git
$ cd bakery
$ gem install bundler
$ bundle install

Running

To run the project you must provide a filepath that points to a valid order text file. Order text files should have the desired quantity and the code of the product separated by whitespace:

10 VS5
14 MB11
13 CF

Run the project with:

$ ./run samples/order.txt

You should see the following output:

10 VS5 $17.98
  2 x 5 $8.99
14 MB11 $54.80
  1 x 8 $24.95
  3 x 2 $9.95
13 CF $25.85
  2 x 5 $9.95
  1 x 3 $5.95

Development

The testing in this project is carried out using RSpec. Style guidelines and recommendations are taken from Better Specs.

To run the test suite:

$ rspec

This project is developed using the ruby-style-guide. The RuboCop gem helps to enforce this style.

To run rubocop against the code base run:

$ rubocop

As recommended in the ruby-style-guide, the project follows the rdoc comment style.

To generate the documentation run:

$ rdoc --all --main README.md

To view the docs via browser:

$ ruby -run -e httpd doc -p 8080

Licence

This project, bakery, is licensed under the GNU Lesser General Public Licence.

bakery's People

Watchers

James Cloos avatar Brett Clark avatar

bakery's Issues

Improve line solver algorithm.

I have a feeling that the line solver algorithm may not perform in the most efficient way. For example, say we have a quantity of 20 and we're trying to solve for packs.

We have possible packs 8 and 3.

In the order we have [8,8], which gives us a remainder of 4. We add 3, giving [8,8,3]. This gives a remainder of 1 which can't be solved, so we pop off the last pack and we've run out of packs so we pop off another and try [8,3]. The new quantity is then 9. So we call solve_order(packs, 9) which will first try to add 8, so we get [8,3,8]. We have already tried this arrangement [8,8,3].

By only passing packs to solve_order which are equal to or smaller than the last pack in the order, we can stop the solver from trying to add 8 after it has added 3.

By adding logging to this algorithm, we can get a good view on what is happening.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.