GithubHelp home page GithubHelp logo

devmarius / fairdivision.js Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 7 KB

Class FairDivision is responsible for fair allocation of items among players based on bids made by each player.

JavaScript 100.00%

fairdivision.js's Introduction

FairDivision.js

Class FairDivision is responsible for fair allocation of items among players based on bids made by each player.

// Example usage

const items = ['Item A', 'Item B', 'Item C', 'Item D'];
const players = [
  { name: 'Bob', bids: [10000, 2000, 500, 800] },
  { name: 'Carol', bids: [4000, 1000, 1500, 2000] },
  { name: 'Ted', bids: [7000, 4000, 2000, 1000] },
];

const fairDivision = new FairDivision(items, players);
fairDivision.adjustedWinner();
fairDivision.printFinalAllocation();

"Fairness" in the context of analyzing this algorithm typically refers to the concept of "fair division", which is well-defined in economics and game theory.

The basic idea is that resources should be allocated in such a way that every participant receives a "fair share" which they subjectively perceive as equal to or better than anyone else's share.

The two main types of fair division that are implemented in this class are:

  1. Adjusted Winner Method: This method involves allocating resources in such a way that each player receives a bundle of resources that, in total, he values at least as much as any other player. This value is calculated based on the individual bids of the player.

  2. Proportional Allocation: In this method, resources are allocated proportionally according to player bids. Each player receives a fraction of resources in proportion to their bid compared to the total of all bids.

Both of these methods guarantee a certain level of fairness, although they may lead to different outcomes depending on circumstances. It's important to understand, however, that "fairness" is measured here subjectively, based on the individual preferences of the players.

Other examples:

  1. Division of property after divorce:
// Define various high-value assets to be divided
const items = ['House', 'Car', 'Jewelry Set', 'Bank Account', 'Vacation Home', 'Boat'];
 
// Add inputs for both spouses and their lawyers
const players = [
  { name: 'Spouse 1', bids: [80000, 20000, 30000, 70000, 50000, 40000] },
  { name: 'Spouse 2', bids: [60000, 30000, 50000, 60000, 40000, 80000] },
  { name: 'Lawyer for Spouse 1', bids: [70000, 25000, 35000, 65000, 55000, 45000] },
  { name: 'Lawyer for Spouse 2', bids: [65000, 35000, 55000, 65000, 45000, 85000] }
];

// Use adjustedWinner method to fairly divide the assets
const fairDivision = new FairDivision(items, players);
fairDivision.adjustedWinner();
fairDivision.printFinalAllocation();
  1. Division of resources in the company:
// Define various high-value assets to be divided
const items = ['Office Building', 'Company Car', 'Equipment', 'Unused Funds', 'Patents', 'Brand'];
 
// Add inputs for both spouses and their lawyers
const players = [
  { name: 'Shareholder', bids: [0, 20000, 30000, 70000, 50000, 100000] },
  { name: 'Creditor', bids: [60000, 30000, 50000, 80000, 100000, 0] },
  { name: 'Employees', bids: [70000, 15000, 35000, 65000, 0, 0] }
];

// Use adjustedWinner method to fairly divide the assets
const fairDivision = new FairDivision(items, players);
fairDivision.adjustedWinner();
fairDivision.printFinalAllocation();

fairdivision.js's People

Contributors

devmarius avatar

Watchers

 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.