Git Product home page Git Product logo

yitzi2 / constrained-randomizer Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 40 KB

The Constrained Randomizer function takes a budget and an array of costs for various items, and uniformly randomly selects a number of each item such that the total remains under budget. (The constraint is thus the same as in the unbounded knapsack problem, but rather than optimizing the task is to randomly select a within-constraint solution such that every such solution has equal probability.)

License: GNU General Public License v3.0

C++ 100.00%

constrained-randomizer's Introduction

Constrained-Randomizer

This project is based on work I originally did for my unofficial patch to the game Sid Meier's Alpha Centauri. (More information about said patch can be found at http://alphacentauri2.info/wiki/Yitzi's_patch (external link).) The original was therefore written in assembly language; it has been translated to C++, and modified to allow for broader usage.

The Constrained_randomizer function takes a budget and an array of costs for various items, and randomly selects a number of each item such that the total remains under budget. (This therefore bears a superficial resemblance to the unbounded knapsack problem, but differs in that the task being performed is not one of optimization, but rather randomization.) The random selection is unbiased: Each valid possibility has equal likelihood (within the limitations of the underlying random number generator).

Also included/to be included in the repository are:

  • A sample.cpp file that contains a main() function allowing the repository contents (.h and .cpp files) to be compiled into a usable program

  • A performance.md file estimating some features of the algorithm's performance under various input conditions

It is also worth noting that, while the function yields a random solution, a maximal solution (i.e. one such that adding any item would exceed the constraint) can be achieved by calling the function on all but the lowest-cost item, and then using the remaining budget to determine the quantity of this last item.

constrained-randomizer's People

Contributors

yitzi2 avatar

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.