補遺3

optseq.pyの変更

startとcompletionを表示するには、次のようにoptseq.pyの3か所を変更します。


001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102

%optseq.py
 :
    def writeExcel(self, filename="optseq_chart.csv", scale=1):
        """
        Output the gantt's chart as a csv file for printing using Excel.

            - Argument:
                - filename: Output file name. Default="optseq_chart.csv."

            - Example usage:

            >>> model.writeExcel("sample.csv")

        """
        f = open(filename, "w")
        horizon = 0
        actList = []
        for a in self.activities:
            actList.append(a)
            act = self.activities[a]
            horizon = max(act.completion, horizon)
        # print("planning horizon=",horizon)
        if scale <= 0:
            print("optseq write scale error")
            exit(0)
        original_horizon = horizon
        horizon = int(horizon/scale)+1
        actList.sort()
        title = " activity ,   mode,".center(20)+" duration,"
        width = len(str(horizon))  # period width =largest index of time
        for t in range(horizon):
            num = str(t+1)
            title += num.rjust(width)+","
        f.write(title+"\n")
        for a in actList:  # sorted order
            act = self.activities[a]  # act: activity object
            actstring = act.name.center(10)[:10]+","
            if len(act.modes) >= 2:
                actstring += str(act.selected.name).center(10)+","
                actstring += str(self.modes[act.selected.name].duration).center(10)+","
            else:
                actstring += str(act.modes[0].name).center(10)[:10]+","
                actstring += str(act.modes[0].duration).center(10)+","
            execute = [0 for t in range(horizon)]
            for (s, c) in act.execute:
                para = act.execute[s, c]
                for t in range(s, c):
                    t2 = int(t/scale)
                    execute[t2] = int(para)
            for t in range(horizon):
                if execute[t] >= 2:
                    actstring += "*"+str(execute[t]).rjust(width-1)+","
                elif execute[t] == 1:
                    actstring += ""+"="*(width)+","
                elif t >= int(act.start/scale) and t < int(act.completion/scale):
                    actstring += ""+"."*(width)+","
                else:
                    actstring += ""+" "*width+","
            f.write(actstring+"\n")
        resList = []
        for r in self.resources:
            resList.append(r)
        resList.sort()

        for r in resList:
            res = self.resources[r]
            if len(res.terms) == 0:  # output residual and capacity
                rstring = res.name.center(30)+", , ,"
                cap = [0 for t in range(horizon)]
                residual = [0 for t in range(horizon)]
                for (s, c) in res.residual:
                    amount = res.residual[(s, c)]
                    if c == "inf":
                        c = horizon
                    s = min(s, original_horizon)
                    c = min(c, original_horizon)
                    s2 = int(s/scale)
                    c2 = int(c/scale)
                    for t in range(s2, c2):
                        residual[t] += amount

                for (s, c) in res.capacity:
                    amount = res.capacity[(s, c)]
                    if c == "inf":
                        c = horizon
                    s = min(s, original_horizon)
                    c = min(c, original_horizon)
                    s2 = int(s/scale)
                    c2 = int(c/scale)
                    for t in range(s2, c2):
                        cap[t] += amount

                for t in range(horizon):
                    # num=str(cap[t]-residual[t])
                    rstring += str(residual[t]) + ","
                f.write(rstring+"\n")

                # rstring= str(" ").center(30)+", , ,"
                #
                # for t in range(horizon):
                #    num=str(cap[t])
                #    rstring+=""+num.rjust(width) +","
                # f.write(rstring+"\n")
        f.close()

その1


029
029

#       title = " activity ,   mode,".center(20)+" duration,"
        title=" activity,"+" mode,"+" start,"+" duration,"+" completion,"        

その2


037
038
039
040
041
042
043
037
038
039
040
040a
040b
041
042
043
043a
043b

#           actstring = act.name.center(10)[:10]+","
#           if len(act.modes) >= 2:
#               actstring += str(act.selected).center(10)+","
#               actstring += str(self.modes[act.selected].duration).center(10)+","
#           else:
#               actstring += str(act.modes[0].name).center(10)[:10]+","
#               actstring += str(act.modes[0].duration).center(10)+","
            actstring = act.name + ","
            if len(act.modes)>=2:
                actstring+=str(act.selected)+","
                actstring+=str(act.start)+","
                actstring+=str(self.modes[act.selected].duration)+","
                actstring+=str(act.completion)+","                
            else:
                actstring += str(act.modes[0].name) + ","
                actstring += str(act.start) + ","
                actstring += str(act.modes[0].duration)+","  
                actstring+=str(act.completion)+","                  

その3


068
068

#               rstring = res.name.center(30)+", , ,"
                rstring = ", , , ,"+res.name+","