def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple # Determine log level loglevel = int(Parameter.getValue('plan.loglevel', database, 0)) if cls.task and cls.task.user: maxloglevel = cls.task.user.getMaxLoglevel(database) if loglevel > maxloglevel: loglevel = maxloglevel # Propagate the operationplan status frepple.solver_propagateStatus(loglevel=loglevel).solve() # Update the feasibility flag of all operationplans for oper in frepple.operations(): for opplan in oper.operationplans: opplan.updateFeasible() # Report the result print("Initial problems:") probs = {} for i in frepple.problems(): if i.name in probs: probs[i.name] += 1 else: probs[i.name] = 1 for i in sorted(probs.keys()): print(" %s: %s" % (i, probs[i]))
def exportProblems(self): if self.verbosity: logger.info("Exporting problems...") starttime = time() cursor = connections[self.database].cursor() with tempfile.TemporaryFile(mode="w+t", encoding='utf-8') as tmp: for i in frepple.problems(): if isinstance(i.owner, frepple.operationplan): owner = i.owner.operation else: owner = i.owner if self.cluster != -1 and owner.cluster != self.cluster: continue print( ("%s\t%s\t%s\t%s\t%s\t%s\t%s" % (i.entity, i.name, owner.name, i.description, str( i.start), str(i.end), round(i.weight, 8))), file=tmp) tmp.seek(0) cursor.copy_from(tmp, 'out_problem', columns=('entity', 'name', 'owner', 'description', 'startdate', 'enddate', 'weight')) tmp.close() if self.verbosity: logger.info('Exported problems in %.2f seconds' % (time() - starttime))
def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple # Determine log level loglevel = int(Parameter.getValue("plan.loglevel", database, 0)) # Propagate the operationplan status logger.info("Propagating work-in-progress status information") frepple.solver_propagateStatus(loglevel=loglevel).solve() # Update the feasibility flag of all operationplans for oper in frepple.operations(): for opplan in oper.operationplans: opplan.updateFeasible() # Report the result print("Initial problems:") probs = {} for i in frepple.problems(): if i.name in probs: probs[i.name] += 1 else: probs[i.name] = 1 for i in sorted(probs.keys()): print(" %s: %s" % (i, probs[i]))
def exportProblems(self): if self.verbosity: logger.info("Exporting problems...") starttime = time() cursor = connections[self.database].cursor() with tempfile.TemporaryFile(mode="w+t", encoding='utf-8') as tmp: for i in frepple.problems(): if isinstance(i.owner, frepple.operationplan): owner = i.owner.operation else: owner = i.owner if self.cluster != -1 and owner.cluster != self.cluster: continue print(("%s\t%s\t%s\t%s\t%s\t%s\t%s" % ( i.entity, i.name, owner.name, i.description, str(i.start), str(i.end), round(i.weight, 8) )), file=tmp) tmp.seek(0) cursor.copy_from( tmp, 'out_problem', columns=('entity', 'name', 'owner', 'description', 'startdate', 'enddate', 'weight') ) tmp.close() if self.verbosity: logger.info('Exported problems in %.2f seconds' % (time() - starttime))
def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple # Determine log level loglevel = int(Parameter.getValue('plan.loglevel', database, 0)) if cls.task and cls.task.user: maxloglevel = cls.task.user.getMaxLoglevel(database) if loglevel > maxloglevel: loglevel = maxloglevel # Propagate the operationplan status frepple.solver_propagateStatus( loglevel=loglevel ).solve() # Update the feasibility flag of all operationplans for oper in frepple.operations(): for opplan in oper.operationplans: opplan.updateFeasible() # Report the result print ("Initial problems:") probs = {} for i in frepple.problems(): if i.name in probs: probs[i.name] += 1 else: probs[i.name] = 1 for i in sorted(probs.keys()): print(" %s: %s" % (i, probs[i]))
def exportProblems(): print("Exporting problems...") starttime = time() writer = csv.writer(open("problems.csv", "wb"), quoting=csv.QUOTE_ALL) writer.writerow(('#entity','name','description','start date','end date','weight')) for i in frepple.problems(): writer.writerow(( i.entity, i.name.encode(encoding,"ignore"), i.owner.name.encode(encoding,"ignore"), i.description.encode(encoding,"ignore"), i.start, i.end, i.weight )) print('Exported problems in %.2f seconds' % (time() - starttime))
def exportProblems(): print("Exporting problems...") starttime = time() writer = csv.writer(open("problems.csv", "w", newline="", encoding="utf-8"), quoting=csv.QUOTE_ALL) writer.writerow( ('#entity', 'name', 'description', 'start date', 'end date', 'weight')) for i in frepple.problems(): writer.writerow((i.entity, i.name, i.owner.name, i.description, i.start, i.end, i.weight)) print('Exported problems in %.2f seconds' % (time() - starttime))
def exportProblems(process): print("Exporting problems...") starttime = time() process.stdin.write('COPY out_problem (entity, name, owner, description, startdate, enddate, weight) FROM STDIN;\n') for i in frepple.problems(): process.stdin.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( i.entity.encode(encoding), i.name.encode(encoding), isinstance(i.owner, frepple.operationplan) and i.owner.operation.name.encode(encoding) or i.owner.name.encode(encoding), i.description.encode(encoding)[0:settings.NAMESIZE + 20], str(i.start), str(i.end), round(i.weight, settings.DECIMAL_PLACES) )) process.stdin.write('\\.\n') print('Exported problems in %.2f seconds' % (time() - starttime))
def exportProblems(process): print("Exporting problems...") starttime = time() process.stdin.write( 'COPY out_problem (entity, name, owner, description, startdate, enddate, weight) FROM STDIN;\n' .encode(encoding)) for i in frepple.problems(): process.stdin.write( ("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (i.entity, i.name, isinstance(i.owner, frepple.operationplan) and i.owner.operation.name or i.owner.name, i.description, str(i.start), str(i.end), round(i.weight, 4))).encode(encoding)) process.stdin.write('\\.\n'.encode(encoding)) print('Exported problems in %.2f seconds' % (time() - starttime))
def exportProblems(cursor): print("Exporting problems...") starttime = time() cursor.executemany( "insert into out_problem \ (entity,name,owner,description,startdate,enddate,weight) \ values(%s,%s,%s,%s,%s,%s,%s)", [( i.entity, i.name, isinstance(i.owner, frepple.operationplan) and str(i.owner.operation) or str(i.owner), i.description[0:settings.NAMESIZE + 20], str(i.start), str(i.end), round(i.weight, settings.DECIMAL_PLACES) ) for i in frepple.problems()] ) cursor.execute("select count(*) from out_problem") print('Exported %d problems in %.2f seconds' % (cursor.fetchone()[0], time() - starttime))
def getData(): for i in frepple.problems(): if isinstance(i.owner, frepple.operationplan): owner = i.owner.operation else: owner = i.owner if self.cluster != -1 and owner.cluster != self.cluster: continue yield "%s\v%s\v%s\v%s\v%s\v%s\v%s\n" % ( clean_value(i.entity), clean_value(i.name), clean_value(owner.name), clean_value(i.description), str(i.start), str(i.end), round(i.weight, 8), )
def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple # Update the feasibility flag of all operationplans for oper in frepple.operations(): for opplan in oper.operationplans: opplan.updateFeasible() # Report the result print("Initial problems:") probs = {} for i in frepple.problems(): if i.name in probs: probs[i.name] += 1 else: probs[i.name] = 1 for i in sorted(probs.keys()): print(" %s: %s" % (i, probs[i]))
def exportProblems(self, process): if self.verbosity: print("Exporting problems...") starttime = time() process( 'COPY out_problem (entity, name, owner, description, startdate, enddate, weight) FROM STDIN;\n' ) for i in frepple.problems(): if isinstance(i.owner, frepple.operationplan): owner = i.owner.operation else: owner = i.owner if self.cluster != -1 and owner.cluster != self.cluster: continue process(("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (i.entity, i.name, owner.name, i.description, str( i.start), str(i.end), round(i.weight, 6)))) process('\\.\n') if self.verbosity: print('Exported problems in %.2f seconds' % (time() - starttime))
def exportProblems(self, process): if self.verbosity: print("Exporting problems...") starttime = time() process.stdin.write('COPY out_problem (entity, name, owner, description, startdate, enddate, weight) FROM STDIN;\n'.encode(self.encoding)) for i in frepple.problems(): if isinstance(i.owner, frepple.operationplan): owner = i.owner.operation else: owner = i.owner if self.cluster != -1 and owner.cluster != self.cluster: continue process.stdin.write(("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( i.entity, i.name, owner.name, i.description, str(i.start), str(i.end), round(i.weight, 6) )).encode(self.encoding)) process.stdin.write('\\.\n'.encode(self.encoding)) if self.verbosity: print('Exported problems in %.2f seconds' % (time() - starttime))
def exportProblems(process): print("Exporting problems...") starttime = time() process.stdin.write( "COPY out_problem (entity, name, owner, description, startdate, enddate, weight) FROM STDIN;\n".encode(encoding) ) for i in frepple.problems(): process.stdin.write( ( "%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( i.entity, i.name, isinstance(i.owner, frepple.operationplan) and i.owner.operation.name or i.owner.name, i.description, str(i.start), str(i.end), round(i.weight, 4), ) ).encode(encoding) ) process.stdin.write("\\.\n".encode(encoding)) print("Exported problems in %.2f seconds" % (time() - starttime))
printModel("output.1.xml") ### print("\nSaving the model to an XML-file") frepple.saveXMLfile("output.2.xml") ### print("\nPrinting some models in XML format") print(mycustomer.toXML()) print(locA.toXML()) print(opplan.toXML()) print(item.toXML()) print(order1.toXML()) print(buf1.toXML()) print(makeoper.toXML()) for i in frepple.problems(): print(i.toXML()) ### print("\nPrinting some models in XML format to a file") with open("output.3.xml", "wt") as output: mycustomer.toXML('P', output) locA.toXML('P', output) opplan.toXML('P', output) item.toXML('P', output) order1.toXML('P', output) buf1.toXML('P', output) makeoper.toXML('P', output) for i in frepple.problems(): i.toXML('P', output)
def printModel(filename): ''' A function that prints out all models to a file. ''' # Open the output file output = open(filename,"wt") # Global settings print("Echoing global settings", file=output) print("Plan name:", frepple.settings.name, file=output) print("Plan description:", frepple.settings.description.encode('utf-8'), file=output) print("Plan current:", frepple.settings.current, file=output) # Solvers print("\nEchoing solvers:", file=output) for b in frepple.solvers(): print(" Solver:", b.name, b.loglevel, getattr(b,'constraints',None), file=output) # Calendars print("\nEchoing calendars:", file=output) for b in frepple.calendars(): print(" Calendar:", b.name, getattr(b,'default',None), file=output) for j in b.buckets: print(" Bucket:", getattr(j,'value',None), j.start, j.end, j.priority, file=output) # Customers print("\nEchoing customers:", file=output) for b in frepple.customers(): print(" Customer:", b.name, b.description, b.category, b.subcategory, b.owner, file=output) # Locations print("\nEchoing locations:", file=output) for b in frepple.locations(): print(" Location:", b.name, b.description, b.category, b.subcategory, b.owner, file=output) # Items print("\nEchoing items:", file=output) for b in frepple.items(): print(" Item:", b.name, b.description, b.category, b.subcategory, b.owner, b.operation, file=output) # Resources print("\nEchoing resources:", file=output) for b in frepple.resources(): print(" Resource:", b.name, b.description, b.category, b.subcategory, b.owner, file=output) for l in b.loads: print(" Load:", l.operation.name, l.quantity, l.effective_start, l.effective_end, file=output) for l in b.loadplans: print(" Loadplan:", l.operationplan.id, l.operationplan.operation.name, l.quantity, l.startdate, l.enddate, file=output) # Buffers print("\nEchoing buffers:", file=output) for b in frepple.buffers(): print(" Buffer:", b.name, b.description, b.category, b.subcategory, b.owner, file=output) for l in b.flows: print(" Flow:", l.operation.name, l.quantity, l.effective_start, l.effective_end, file=output) for l in b.flowplans: print(" Flowplan:", l.operationplan.id, l.operationplan.operation.name, l.quantity, l.date, file=output) # Operations print("\nEchoing operations:", file=output) for b in frepple.operations(): print(" Operation:", b.name, b.description, b.category, b.subcategory, file=output) for l in b.loads: print(" Load:", l.resource.name, l.quantity, l.effective_start, l.effective_end, file=output) for l in b.flows: print(" Flow:", l.buffer.name, l.quantity, l.effective_start, l.effective_end, file=output) if isinstance(b, frepple.operation_alternate): for l in b.alternates: print(" Alternate:", l.name, file=output) if isinstance(b, frepple.operation_routing): for l in b.steps: print(" Step:", l.name, file=output) # Demands print("\nEchoing demands:", file=output) for b in frepple.demands(): print(" Demand:", b.name, b.due, b.item.name, b.quantity, file=output) for i in b.operationplans: print(" Operationplan:", i.id, i.operation.name, i.quantity, i.end, file=output) # Operationplans print("\nEchoing operationplans:", file=output) for b in frepple.operationplans(): print(" Operationplan:", b.operation.name, b.quantity, b.start, b.end, file=output) for s in b.operationplans: print(" ", s.operation.name, s.quantity, s.start, s.end, file=output) # Problems print("\nPrinting problems", file=output) for i in frepple.problems(): print(" Problem:", i.entity, i.name, i.description, i.start, i.end, i.weight, file=output)
printModel("output.1.xml") ### print("\nSaving the model to an XML-file") frepple.saveXMLfile("output.2.xml") ### print("\nPrinting some models in XML format") print(mycustomer.toXML()) print(locA.toXML()) print(opplan.toXML()) print(item.toXML()) print(order1.toXML()) print(buf1.toXML()) print(makeoper.toXML()) for i in frepple.problems(): print(i.toXML()) ### print("\nPrinting some models in XML format to a file") with open("output.3.xml","wt") as output: mycustomer.toXML('P',output) locA.toXML('P',output) opplan.toXML('P',output) item.toXML('P',output) order1.toXML('P',output) buf1.toXML('P',output) makeoper.toXML('P',output) for i in frepple.problems(): i.toXML('P',output)
def printModel(filename): ''' A function that prints out all models to a file. ''' # Open the output file with open(filename, "wt", encoding='utf-8') as output: # Global settings print("Echoing global settings", file=output) print("Plan name:", frepple.settings.name, file=output) print("Plan description:", frepple.settings.description, file=output) print("Plan current:", frepple.settings.current, file=output) # Solvers print("\nEchoing solvers:", file=output) for b in frepple.solvers(): print(" Solver:", b.name, b.loglevel, getattr(b, 'constraints', None), file=output) # Calendars print("\nEchoing calendars:", file=output) for b in frepple.calendars(): print(" Calendar:", b.name, getattr(b, 'default', None), file=output) for j in b.buckets: print(" Bucket:", getattr(j, 'value', None), j.start, j.end, j.priority, file=output) # Customers print("\nEchoing customers:", file=output) for b in frepple.customers(): print(" Customer:", b.name, b.description, b.category, b.subcategory, b.owner, file=output) # Locations print("\nEchoing locations:", file=output) for b in frepple.locations(): print(" Location:", b.name, b.description, b.category, b.subcategory, b.owner, file=output) # Items print("\nEchoing items:", file=output) for b in frepple.items(): print(" Item:", b.name, b.description, b.category, b.subcategory, b.owner, b.operation, file=output) # Resources print("\nEchoing resources:", file=output) for b in frepple.resources(): print(" Resource:", b.name, b.description, b.category, b.subcategory, b.owner, file=output) for l in b.loads: print(" Load:", l.operation.name, l.quantity, l.effective_start, l.effective_end, file=output) for l in b.loadplans: print(" Loadplan:", l.operationplan.id, l.operationplan.operation.name, l.quantity, l.startdate, l.enddate, file=output) # Buffers print("\nEchoing buffers:", file=output) for b in frepple.buffers(): print(" Buffer:", b.name, b.description, b.category, b.subcategory, b.owner, file=output) for l in b.flows: print(" Flow:", l.operation.name, l.quantity, l.effective_start, l.effective_end, file=output) for l in b.flowplans: print(" Flowplan:", l.operationplan.id, l.operationplan.operation.name, l.quantity, l.date, file=output) # Operations print("\nEchoing operations:", file=output) for b in frepple.operations(): print(" Operation:", b.name, b.description, b.category, b.subcategory, file=output) for l in b.loads: print(" Load:", l.resource.name, l.quantity, l.effective_start, l.effective_end, file=output) for l in b.flows: print(" Flow:", l.buffer.name, l.quantity, l.effective_start, l.effective_end, file=output) if isinstance(b, frepple.operation_alternate): for l in b.alternates: print(" Alternate:", l[0].name, l[1], l[2], l[3], file=output) if isinstance(b, frepple.operation_routing): for l in b.steps: print(" Step:", l.name, file=output) # Demands print("\nEchoing demands:", file=output) for b in frepple.demands(): print(" Demand:", b.name, b.due, b.item.name, b.quantity, file=output) for i in b.operationplans: print(" Operationplan:", i.id, i.operation.name, i.quantity, i.end, file=output) # Operationplans print("\nEchoing operationplans:", file=output) for b in frepple.operationplans(): print(" Operationplan:", b.operation.name, b.quantity, b.start, b.end, file=output) for s in b.operationplans: print(" ", s.operation.name, s.quantity, s.start, s.end, file=output) # Problems print("\nPrinting problems", file=output) for i in frepple.problems(): print(" Problem:", i.entity, i.name, i.description, i.start, i.end, i.weight, file=output)