Exemplo n.º 1
0
def main():
    config.initializeConfig()
    if len(sys.argv) < 3:
        print 'USAGE:', sys.argv[0], USAGE
        # sys.exit(0)
        myVrp, solutions, myStyleSheet = None, None, None
    else:
        # type of input data we're working on
        toks = sys.argv[1].split(':')
        type = toks[0]
        subtype = toks[1] if len(toks) > 1 else 'default'
        # solutions to load and their subtype
        if len(sys.argv) > 3 and sys.argv[3][0] == ':':
            solutionSubtype = sys.argv[3][1:]
            solutionFileNames = sys.argv[4:]
        elif len(sys.argv) > 2:
            solutionSubtype = 'default'
            solutionFileNames = sys.argv[3:]
        else:
            solutionFileNames = False
        # loader object to load all of this
        loader = loaddata.DataLoader()
        # here we load the data
        myVrp = loader.loadInstance(sys.argv[2], type, subtype)
        # reorder solutions using numbers in file names
        if solutionFileNames:
            solutionFileNames = util.reorder(solutionFileNames)
            solutions = [
                loader.loadSolution(fName, myVrp, type, solutionSubtype)
                for fName in solutionFileNames
            ]
        else:
            solutions = None
        myStyleSheet = loader.loadStyleSheet(type)


#         myStyleSheet = loaddata.stylesheetFromType(type)
#     myStyleSheet = stylesheet.FunkyStyleSheet()
    app = wxgui.vrpgui.VrpGui(myVrp, solutions, myStyleSheet)
    app.MainLoop()
Exemplo n.º 2
0
def loadDataInteractively(problemType=None,
                          instanceType=None,
                          instanceFileName=None,
                          solutionType=None,
                          solutionFileNames=None):
    import loadfiles
    import loaddata
    fileLoader = loadfiles.LoadDataDialog(None, problemType, instanceType,
                                          instanceFileName, solutionType,
                                          solutionFileNames)
    while True:
        returnValue = fileLoader.ShowModal()
        if returnValue == wx.ID_OK:
            type = fileLoader.typeChoice.GetStringSelection()
            instanceType = fileLoader.instanceTypeChoice.GetStringSelection()
            solutionType = fileLoader.solutionTypeChoice.GetStringSelection()
            loader = loaddata.DataLoader()
            fName = fileLoader.instanceNameField.GetValue()
            try:
                myVrp = loader.loadInstance(fName, type, instanceType)
                solutionFNames = \
                    eval(fileLoader.solutionsNameField.GetValue()) \
                    if fileLoader.solutionsNameField.GetValue() else []
                mySolutions = [
                    loader.loadSolution(fName, myVrp, type, solutionType)
                    for fName in solutionFNames
                ]
                myStyleSheet = loader.loadStyleSheet(type)
                fileLoader.Destroy()
                return myVrp, mySolutions, myStyleSheet
            except Exception as ex:
                dialog = wx.MessageDialog(
                    None, 'Error while loading data: ' + str(ex),
                    'Unable to load data!@#', wx.OK | wx.ICON_ERROR)
                dialog.ShowModal()
                dialog.Destroy()
        else:
            return None, None, None
Exemplo n.º 3
0
 def __init__(self, parent):
     wx.Dialog.__init__(self, parent, -1, title='Save stylesheet')
     # layout for this dialog
     mainSizer = wx.FlexGridSizer(3, 2, 10, 10)
     # first line: sheet name
     label = wx.StaticText(self, -1, 'Stylesheet name:')
     self.sheetName = wx.TextCtrl(self, size=(self.GetSize()[0] / 2, 22))
     self.sheetName.SetValue(parent.styleSheet.__module__)
     self.sheetName.Bind(wx.EVT_TEXT, self.onTextEntry)
     #
     mainSizer.Add(label, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
     mainSizer.Add(self.sheetName, 0, wx.ALIGN_LEFT | wx.ALL | wx.EXPAND, 5)
     # second line: problems for which this sheet should be the default sheet
     label = wx.StaticText(self, -1, 'Used as default sheet for:')
     # we need this object to find out what we can load
     loader = loaddata.DataLoader()
     availableTypes = loader.getAvailableTypes()
     self.problemList = wx.CheckListBox(self, choices=availableTypes)
     self.problemList.SetChecked([
         i for i, t in enumerate(availableTypes)
         if t in parent.styleSheet.defaultFor
     ])
     mainSizer.Add(label, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
     mainSizer.Add(self.problemList, 0, wx.EXPAND, 5)
     # add standard dialog buttons
     self.okButton = wx.Button(self, wx.ID_OK)
     if self.sheetName.GetValue() == '':
         self.okButton.Disable()
     cancelButton = wx.Button(self, wx.ID_CANCEL)
     mainSizer.Add(self.okButton, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
     #         mainSizer.Add((20,0), 1)
     mainSizer.Add(cancelButton, 0, wx.ALIGN_LEFT | wx.ALL, 5)
     # now we're ready
     self.SetSizer(mainSizer)
     mainSizer.Fit(self)
     self.CenterOnScreen()
Exemplo n.º 4
0
    def __init__(self,
                 parent,
                 problemType=None,
                 instanceType=None,
                 instanceFileName=None,
                 solutionType=None,
                 solutionFileNames=None):
        wx.Dialog.__init__(self,
                           parent,
                           -1,
                           title='Choose an instance and solutions!')
        # we need this object to find out what we can load
        self.loader = loaddata.DataLoader()
        availableTypes = self.loader.getAvailableTypes()
        # layout for this dialog
        mainSizer = wx.GridSizer(0, 2, 10, 10)
        # first line: problem type
        label = wx.StaticText(self, -1, 'Problem type:')
        self.typeChoice = wx.Choice(
            self,
            -1,
            choices=availableTypes,
            #                                     size=(150, 25)
        )
        mainSizer.Add(label, 0,
                      wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        mainSizer.Add(self.typeChoice, 0,
                      wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        # second line: instance type
        label = wx.StaticText(self, -1, 'Instance type:')
        self.instanceTypeChoice = wx.Choice(self, -1)  #, size=(150, 25))
        mainSizer.Add(label, 0,
                      wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        mainSizer.Add(self.instanceTypeChoice, 0,
                      wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        # third line: load an instance
        self.instanceFileButton = wx.Button(self, -1, 'Select instance')
        mainSizer.Add(self.instanceFileButton, 0,
                      wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        self.Bind(wx.EVT_BUTTON, self.onInstanceButton,
                  self.instanceFileButton)
        self.instanceNameField = wx.TextCtrl(self, size=(200, -1))
        mainSizer.Add(self.instanceNameField, 0,
                      wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        # fourth line: solution subtype
        label = wx.StaticText(self, -1, 'Solution type:')
        self.solutionTypeChoice = wx.Choice(self, -1)  #, size=(150, 25))
        mainSizer.Add(label, 0,
                      wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        mainSizer.Add(self.solutionTypeChoice, 0,
                      wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        # fifth line: load a solution
        solutionFilesButton = wx.Button(self, -1, 'Select solutions')
        mainSizer.Add(solutionFilesButton, 0,
                      wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        self.Bind(wx.EVT_BUTTON, self.onSolutionButton, solutionFilesButton)
        self.solutionsNameField = wx.TextCtrl(self, size=(200, -1))
        mainSizer.Add(self.solutionsNameField, 0,
                      wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        # set default problem type if specified
        if problemType:
            self.typeChoice.SetSelection(availableTypes.index(problemType))
            self.typeChoice.Disable()
        # update choice lists
        self.updateChoice()
        # files we want to load
        self.instanceFile = None
        self.solutionFiles = []
        # set default selections if specified
        if problemType and instanceType:
            availableInstanceTypes = \
                self.loader.getAvailableInstanceTypes(problemType)
            self.instanceTypeChoice.SetSelection( \
                availableInstanceTypes.index(instanceType))
            self.instanceTypeChoice.Disable()
        if instanceFileName:
            self.instanceNameField.SetValue(instanceFileName)
            self.instanceNameField.Disable()
            self.instanceFileButton.Disable()
        if problemType and solutionType:
            availableSolutionTypes = \
                self.loader.getAvailableSolutionTypes(problemType)
            self.solutionTypeChoice.SetSelection( \
                availableSolutionTypes.index(solutionType))
        if solutionFileNames:
            self.solutionsNameField.SetValue(solutionFileNames)

        # add standard dialog buttons
        self.okButton = wx.Button(self, wx.ID_OK)
        self.okButton.Disable()
        cancelButton = wx.Button(self, wx.ID_CANCEL)
        mainSizer.Add(self.okButton, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
        #         mainSizer.Add((20,0), 1)
        mainSizer.Add(cancelButton, 0, wx.ALIGN_LEFT | wx.ALL, 5)
        # now we're ready
        self.SetSizer(mainSizer)
        #         self.SetSize((400,500))
        mainSizer.Fit(self)
        self.CenterOnScreen()

        # update instance and solution type choice when appropriate
        self.Bind(wx.EVT_CHOICE, self.onTypeChoice, self.typeChoice)
Exemplo n.º 5
0
    else:
        # type of input data we're working on
        toks = sys.argv[1].split(':')
        type = toks[0]
        subtype = toks[1] if len(toks) > 1 else 'default'
        # solutions to load and their subtype
        if sys.argv[3][0] == ':':
            solutionSubtype = sys.argv[3][1:]
            solutionFileName = sys.argv[4]
        else:
            solutionSubtype = 'default'
            solutionFileName = sys.argv[3]
        # in case an output file name is provided
        if (sys.argv[3][0] == ':' and len(sys.argv) == 6) or \
           (sys.argv[3][0] != ':' and len(sys.argv) == 5):
            outputFileName = sys.argv[-1]
        # loader object to load all of this
        loader = loaddata.DataLoader()
        # here we load the data
        myVrp = loader.loadInstance(sys.argv[2], type, subtype)
        mySolution = loader.loadSolution(solutionFileName, myVrp,
                                         type, solutionSubtype)
        myStyleSheet = loader.loadStyleSheet(type)
        # now we can paint it to a PDF canvas
        width, height = myVrp.width, myVrp.height
        canvas = ReportlabCanvas(width, height, outputFileName)
        myStyleSheet.paint( myVrp, mySolution, canvas )
        canvas.canvas.showPage()
        canvas.canvas.save()
        print 'Saved to', outputFileName