Go to login Go to sub menu Go to text

데이터 구조 및 분석: Linear Structure and Dynamic Programming

임시 이미지 KAIST 산업및시스템공학과 문일철
http://kaist.edwith.org/datastructure-2019s/forum/27239
Thumb up 1168 Learner 2213

코드를 작성하고 그래프를 뽑아내는 것 까지는 성공을 했습니다. 하지만 제 코드가 맞는지 잘 모르겠고 그래프를 그릴 때마다 랜덤하게 그려집니다. 원래 랜덤하게 그려지는 것이 맞는 건가요?

class PlanNode:
def __init__(self, numNo, strSerialNumber, strModel, numModelNumber, dateStart, numAssemblyOrder, dateEnd,
strOrderOrigin):
self.numNo = numNo
self.strSerialNumber = strSerialNumber
self.strModel = strModel
self.numModelNumber = numModelNumber
self.dateStart = dateStart
self.numAssemblyOrder = numAssemblyOrder
self.dateEnd = dateEnd
self.strOrderOrigin = strOrderOrigin

def printOut(self):
print('No :', self.numNo, ', SerialNum : ', self.strSerialNumber, ',Model:', self.strModel, ',Start Date:',
self.dateStart)

def getNextNode(self):
# Problem 1. complete this method
nextNode = None
return self.nextNode

def getPrevNode(self):
# Problem 1. complete this method
prevNode = ''
return self.prevNode

def setNextNode(self, node):
# Problem 1. complete this method
self.nextNode = node

def setPrevNode(self, node):
# Problem 1. complete this method
self.prevNode = node
from PlanNode import PlanNode

import matplotlib.pyplot as plt
import numpy as np
class ProductionList():
def __init__(self, Filename):

self.nodeHead = PlanNode(-1, '', '', '', '', '', '', '')
self.nodeTail = PlanNode(-1, '', '', '', '', '', '', '')

# Problem 2. setup the node relations between the nodeTail and nodeHead in
# the properties. Use setNextNode and setPrevNode method of
# the nodes

self.nodeHead.setNextNode(self.nodeTail)
self.nodeTail.setPrevNode(self.nodeHead)

f = open(Filename)
temp = f.readlines()
f.close()

dataset = []
for row in temp:
dataset.append(row[:-1].split(','))
Dataset = np.asarray(dataset[1:]).T

numNos = Dataset[0].astype('int')
strSerialNumbers = Dataset[1].astype('str')
strModels = Dataset[2].astype('str')
numModelNumbers = Dataset[3].astype('int')
dateStart = Dataset[4].astype('str')
numAssemblyOrders = Dataset[5].astype('int')
dateEnd = Dataset[6].astype('str')
strOrderOrigins = Dataset[7].astype('str')

for i in range(len(numNos)):
node = PlanNode(numNos[i], strSerialNumbers[i], strModels[i], numModelNumbers[i], dateStart[i],
numAssemblyOrders[i], dateEnd[i], strOrderOrigins[i])
node.printOut()
self.addLast(node)

self.showPlanChart()

def addLast(self, node):
# Problem 3. complete the method to add the node in the parameter to the
# last of the linked list. The tail should be always at the
# last, so the node in the parameter should be the previous
# node of the tail

nodeLast = self.nodeTail.getPrevNode()
nodeLast.setNextNode(node)
node.setNextNode(self.nodeTail)
node.setPrevNode(nodeLast)
self.nodeTail.setPrevNode(node)

def showPlanChart(self):

allStartDate = []
allModel = []
node = self.nodeHead

# Problem 4. iterate from nodeHead to nodeTail to retrieve the
# start data and the model of all plan nodes.
while node.getNextNode() != self.nodeTail:
node = node.getNextNode()
allStartDate.append(node.dateStart)
allModel.append(node.strModel)

plt.figure(1)
plt.subplot(211)
Uniq_allModel = list(set(allModel))
Counting_allModel = [allModel.count(a) for a in Uniq_allModel]
xlabel = [i for i in range(len(Uniq_allModel))]
plt.bar(xlabel[0:10], Counting_allModel[0:10], align='center')
plt.xticks(xlabel[0:10], Uniq_allModel[0:10])
plt.xlabel('Model')
plt.ylabel('Number of Orders')

plt.subplot(212)
Uniq_allStartDate = list(set(allStartDate))
Counting_dateStart = [allStartDate.count(a) for a in Uniq_allStartDate]
xlabel = [i for i in range(len(Uniq_allStartDate))]
plt.bar(xlabel[0:10], Counting_dateStart[0:10], align='center')
plt.xticks(xlabel[0:10], Uniq_allStartDate[0:10])
plt.xlabel('Date')
plt.ylabel('Number of Orders')
plt.show()
from ProductionList import ProductionList

p=ProductionList('Plan-2012.12.17.csv')

comment