CutStock.py

Python Example:


from mplpy import *

from MplCutStock import *


def runCutStock():
   cutStock = MplCutStock()
   dataDir = cutStock.DataDir
   cutNames, cutDemand = readCutWidthsFile(dataDir + "CutWidths.dat")
   patternNames, cutWaste = readCutWasteFile(dataDir + "CutWaste.dat")
   cutsInPattern = readCutPatternsFile1(dataDir + "CutPatterns.dat")
   priceSheet = 28
   sheetsAvail = 2000
   result = cutStock.SolveModel("CoinMP", cutNames, patternNames, priceSheet, sheetsAvail, cutDemand, cutsInPattern)
   if result:
      print(str(cutStock.Solution))
   else:
      print(cutStock.ResultString)


def readCutWidthsFile(filename):
   cutNames = []
   cutDemand = []
   file = open(filename, 'r')
   for i, line in enumerate(file):
      cutNames.append("w" + str(i+1))
      cutDemand.append(int(line.rstrip("\n")))
   file.close()
   return cutNames, cutDemand


def readCutWasteFile(filename):
   patternNames = []
   cutWaste = []
   file = open(filename, 'r')
   for i, line in enumerate(file):
      patternNames.append('p' + str(i+1))
      cutWaste.append(int(line.rstrip("\n")))
   file.close()
   return patternNames, cutWaste


def readCutPatternsFile1(filename):
   cutsInPattern = []
   file = open(filename, 'r')
   for line in file:
      items = line.split(",")
      if len(items) >= 3:
         cutsInPattern.append(items[0])
         cutsInPattern.append(items[1])
         cutsInPattern.append(int(items[2].rstrip("\n")))
   file.close()
   return cutsInPattern


def readCutPatternsFile2(filename):
   patternSubscr = []
   patternValues = []
   file = open(filename, 'r')
   for line in file:
      items = line.split(",")
      if len(items) >= 3:
         patternSubscr.append(items[0])
         patternSubscr.append(items[1])
         patternValues.append(int(items[2].rstrip("\n")))
   file.close()
   return patternSubscr, patternValues


if __name__ == '__main__':
   runCutStock()


        

Back To Top | Maximal Home Page | List of Samples | Previous Page | Next Page