Buckets:
| # Code automatically generated from OptiMUS | |
| # Problem type: LP | |
| # Problem description | |
| ''' | |
| An art store produces large and small art pieces. Each large art piece requires | |
| PaintPerLarge units of paint, GlitterPerLarge units of glitter, and GluePerLarge | |
| units of glue. Each small art piece requires PaintPerSmall units of paint, | |
| GlitterPerSmall units of glitter, and GluePerSmall units of glue. The store has | |
| AvailablePaint units of paint, AvailableGlitter units of glitter, and | |
| AvailableGlue units of glue available. The store must produce at least MinLarge | |
| large art pieces and at least MinSmall small art pieces. The objective is to | |
| maximize profit, where each large art piece generates ProfitLarge and each small | |
| art piece generates ProfitSmall. | |
| ''' | |
| # Import necessary libraries | |
| import json | |
| from gurobipy import * | |
| # Create a new model | |
| model = Model() | |
| # Load data | |
| with open("parameters.json", "r") as f: | |
| data = json.load(f) | |
| # @Def: definition of a target | |
| # @Shape: shape of a target | |
| # Parameters | |
| # @Parameter AvailablePaint @Def: Total units of paint available @Shape: [] | |
| AvailablePaint = data['AvailablePaint'] | |
| # @Parameter AvailableGlitter @Def: Total units of glitter available @Shape: [] | |
| AvailableGlitter = data['AvailableGlitter'] | |
| # @Parameter AvailableGlue @Def: Total units of glue available @Shape: [] | |
| AvailableGlue = data['AvailableGlue'] | |
| # @Parameter PaintPerLarge @Def: Units of paint required to make one large art piece @Shape: [] | |
| PaintPerLarge = data['PaintPerLarge'] | |
| # @Parameter GlitterPerLarge @Def: Units of glitter required to make one large art piece @Shape: [] | |
| GlitterPerLarge = data['GlitterPerLarge'] | |
| # @Parameter GluePerLarge @Def: Units of glue required to make one large art piece @Shape: [] | |
| GluePerLarge = data['GluePerLarge'] | |
| # @Parameter PaintPerSmall @Def: Units of paint required to make one small art piece @Shape: [] | |
| PaintPerSmall = data['PaintPerSmall'] | |
| # @Parameter GlitterPerSmall @Def: Units of glitter required to make one small art piece @Shape: [] | |
| GlitterPerSmall = data['GlitterPerSmall'] | |
| # @Parameter GluePerSmall @Def: Units of glue required to make one small art piece @Shape: [] | |
| GluePerSmall = data['GluePerSmall'] | |
| # @Parameter ProfitLarge @Def: Profit per large art piece @Shape: [] | |
| ProfitLarge = data['ProfitLarge'] | |
| # @Parameter ProfitSmall @Def: Profit per small art piece @Shape: [] | |
| ProfitSmall = data['ProfitSmall'] | |
| # @Parameter MinLarge @Def: Minimum number of large art pieces to produce @Shape: [] | |
| MinLarge = data['MinLarge'] | |
| # @Parameter MinSmall @Def: Minimum number of small art pieces to produce @Shape: [] | |
| MinSmall = data['MinSmall'] | |
| # Variables | |
| # @Variable NumberLarge @Def: The number of large art pieces to produce @Shape: [] | |
| NumberLarge = model.addVar(lb=MinLarge, vtype=GRB.CONTINUOUS, name="NumberLarge") | |
| # @Variable NumberSmall @Def: The number of small art pieces to produce @Shape: [] | |
| NumberSmall = model.addVar(vtype=GRB.INTEGER, lb=MinSmall, name="NumberSmall") | |
| # Constraints | |
| # @Constraint Constr_1 @Def: Each large art piece requires PaintPerLarge units of paint, and each small art piece requires PaintPerSmall units of paint. | |
| # The total paint used cannot exceed AvailablePaint units. | |
| model.addConstr(PaintPerLarge * NumberLarge + PaintPerSmall * NumberSmall <= AvailablePaint) | |
| # @Constraint Constr_2 @Def: Each large art piece requires GlitterPerLarge units of glitter, and each small art piece requires GlitterPerSmall units of glitter. | |
| # The total glitter used cannot exceed AvailableGlitter units. | |
| model.addConstr(GlitterPerLarge * NumberLarge + GlitterPerSmall * NumberSmall <= AvailableGlitter) | |
| # @Constraint Constr_3 @Def: Each large art piece requires GluePerLarge units of glue, and each small art piece requires GluePerSmall units of glue. | |
| # The total glue used cannot exceed AvailableGlue units. | |
| model.addConstr(GluePerLarge * NumberLarge + GluePerSmall * NumberSmall <= AvailableGlue) | |
| # @Constraint Constr_4 @Def: At least MinLarge large art pieces must be produced. | |
| model.addConstr(NumberLarge >= MinLarge) | |
| # @Constraint Constr_5 @Def: At least MinSmall small art pieces must be produced. | |
| model.addConstr(NumberSmall >= MinSmall) | |
| # Objective | |
| # @Objective Objective @Def: Total profit is the sum of the profits generated by large and small art pieces. | |
| # The objective is to maximize the total profit. | |
| model.setObjective(ProfitLarge * NumberLarge + ProfitSmall * NumberSmall, GRB.MAXIMIZE) | |
| # Solve | |
| model.optimize() | |
| # Extract solution | |
| solution = {} | |
| variables = {} | |
| objective = [] | |
| variables['NumberLarge'] = NumberLarge.x | |
| variables['NumberSmall'] = NumberSmall.x | |
| solution['variables'] = variables | |
| solution['objective'] = model.objVal | |
| with open('solution.json', 'w') as f: | |
| json.dump(solution, f, indent=4) |
Xet Storage Details
- Size:
- 4.76 kB
- Xet hash:
- 3aecd5669d9bc0c0b62f3691cd903ca0d62afcf1a6c1e9ff1ee474088dc0d1b8
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.