Manuals/calci/Exampleslp

Revision as of 03:41, 28 September 2018 by Sahiti (talk | contribs)
Linear Programming Examples in z3

DESCRIPTION

  • Basic Linear Programming examples in z3.
  • Reflecting different domains like Engineering, Statistics, Medicine, etc.
  • Testing how we can make better solutions to the standard problems compared to other software.

Examples

ExampleLP1: Chocolate Problem
Shannon's Chocolates produces semisweet chocolate chips and milk chocolate chips at its plants in Wichita, KS and Moore, OK. The Wichita plant produces 3000 pounds of semisweet chips and 2000 pounds of milk chocolate chips each day at a cost of $1000, while the Moore plant produces 1000 pounds of semisweet chips and 6000 pounds of milk chocolate chips each day at a cost of $1500. Shannon has an order from Food Box Supermarkets for at least 30,000 pounds of semisweet chips and 60,000 pounds of milk chocolate chips. How should Shannon schedule its production so that it can fill the order at minimum cost? What is the minimum cost?

z3 code: Chocolate Problem
var solver = require('javascript-lp-solver'),
	results,
    model = {
    "name": "Chocolate Problem",
    "optimize": "cost",
    "opType": "min",
    "constraints": {
        "semisweet": {
            "min": 30000
        },
        "milk chocolate": {
            "min": 60000
        }
    },
    "variables": {
        "Kansas": {
            "semisweet": 3000,
            "milk chocolate": 2000,
            "cost": 1000
        },
        "Oklahoma": {
            "semisweet": 1000,
            "milk chocolate": 6000,
            "cost": 1500
        }
    }
};
    
console.log(solver.Solve(model));
Solution:
{ feasible: true,
  result: 18750,
  bounded: true,
  Kansas: 7.5,
  Oklahoma: 7.5 }


ExampleLP2: Coffee Problem
Fred's Coffee sells two blends of beans: Yusip Blend and Exotic Blend. Yusip Blend is one-half Costa Rican beans and one-half Ethiopian beans. Exotic Blend is one-quarter Costa Rican beans and three-quarters Ethiopian beans. Profit on the Yusip Blend is $3.50 per pound, while profit on the Exotic Blend is $4.00 per pound. Each day Fred receives a shipment of 200 pounds of Costa Rican beans and 330 pounds of Ethiopian beans to use for the two blends. How many pounds of each blend should be prepared each day to maximize profit? What is the maximum profit?

z3 code: Coffee Problem
var solver = require('javascript-lp-solver'),
    results,
    model = {
    "name": "Coffee Problem",
    "optimize": "profit",
    "opType": "max",
    "constraints": {
        "costa": {
            "max": 200
        },
        "ethiopian": {
            "max": 330
        }
    },
    "variables": {
        "yusip": {
            "costa": 0.5,
            "ethiopian": 0.5,
            "profit": 3.5
        },
        "exotic": {
            "costa": 0.25,
            "ethiopian": 0.75,
            "profit": 4
        }
    }
};
console.log(solver.Solve(model));
Solution:
{ feasible: true,
  result: 1985,
  bounded: true,
  yusip: 270,
  exotic: 260 }


ExampleLP3: Farmer Problem
Fred's Coffee sells two blends of beans: Yusip Blend and Exotic Blend. Yusip Blend is one-half Costa Rican beans and one-half Ethiopian beans. Exotic Blend is one-quarter Costa Rican beans and three-quarters Ethiopian beans. Profit on the Yusip Blend is $3.50 per pound, while profit on the Exotic Blend is $4.00 per pound. Each day Fred receives a shipment of 200 pounds of Costa Rican beans and 330 pounds of Ethiopian beans to use for the two blends. How many pounds of each blend should be prepared each day to maximize profit? What is the maximum profit?

z3 code: Farmer Problem
var solver = require('javascript-lp-solver'),
    results,
    model = {
    "name": "farmer Problem",
    "optimize": "profit",
    "opType": "max",
    "constraints": {
        "storage": {
            "max": 15000
        },
        "expense": {
            "max": 4000
        },
		"plant": {
            "max": 75
        }
    },
    "variables": {
        "wheat": {
            "storage": 120,
            "expense": 110,
			"plant": 1,
            "profit": 143
        },
        "barley": {
            "storage": 210,
            "expense": 30,
			"plant": 1,
            "profit": 60
        }
    }
};
console.log(solver.Solve(model));
Solution:
{ feasible: true,
  result: 6315.625,
  bounded: true,
  wheat: 21.875,
  barley: 53.125 }