diff --git a/src/ProblemCristina.py b/src/ProblemCristina.py new file mode 100755 index 0000000..1c9125f --- /dev/null +++ b/src/ProblemCristina.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : + +############################################################################# +# Copyright 2013 by Antonio Gomez and Miguel Cardenas # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################# + +__author__ = ' AUTHORS: Antonio Gomez (antonio.gomez@csiro.au)' + + +__version__ = ' REVISION: 1.0 - 15-01-2014' + +""" +HISTORY + Version 0.1 (12-04-2013): Creation of the file. + Version 1.0 (15-01-2014): Fist stable version. +""" + +import random + +class ProblemCristina(object): + def __init__(self): + return + + def solve(self, solution): + return random.random() + + def extractSolution(self): + raise NotImplementedError("Extract solution abstract problem") + + def finish(self): + raise NotImplementedError("Finish abstract problem") diff --git a/src/SolutionCristina.py b/src/SolutionCristina.py new file mode 100755 index 0000000..897d5e9 --- /dev/null +++ b/src/SolutionCristina.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : + +############################################################################# +# Copyright 2013 by Antonio Gomez and Miguel Cardenas # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################# + +__author__ = ' AUTHORS: Antonio Gomez (antonio.gomez@csiro.au)' + + +__version__ = ' REVISION: 1.0 - 15-01-2014' + +""" +HISTORY + Version 0.1 (17-04-2013): Creation of the file. + Version 1.0 (15-01-2014): Fist stable version. +""" + +from SolutionBase import SolutionBase +import Utils as u + + +class SolutionCristina (SolutionBase): + def __init__(self, infile): + SolutionBase.__init__(self, infile) + #TODO: Implemement how data is initialized + self.__data = None + return + + def initialize(self, data): + self.__data = data + return + + def prepare(self, filename): + self.__data.create_input_file(filename) + + def getNumberofParams(self): + return self.__data.getNumParams() + + def getMaxNumberofValues(self): + return self.__data.getMaxRange() + + def getParameters(self): + return self.__data.getParameters() + + def getParametersValues(self): + return self.__data.getValsOfParameters() diff --git a/src/SolutionsQueue.py b/src/SolutionsQueue.py index 61e9162..a1b52c5 100755 --- a/src/SolutionsQueue.py +++ b/src/SolutionsQueue.py @@ -21,6 +21,7 @@ import os from SolutionFusion import SolutionFusion +from SolutionCristina import SolutionCristina from SolutionNonSeparable import SolutionNonSeparable import Utils as util from Parameter import Parameter @@ -57,6 +58,10 @@ def __init__(self, filename, solution_type, infile, writeToFile, self.__solutionBase = SolutionFusion(self.__infile) util.logger.info("QUEUE: Initialised fusion queue (" + filename + ")" + self.__infile) + if self.__solType == util.solution_type.CRISTINA: + self.__solutionBase = SolutionCristina(self.__infile) + util.logger.info("QUEUE: Initialised Cristina queue (" + + filename + ")" + self.__infile) else: self.__solutionBase = SolutionNonSeparable(self.__infile) util.logger.info("QUEUE: Initialised non separable queue (" + diff --git a/src/SolverDAB.py b/src/SolverDAB.py index 913405e..fabecd0 100644 --- a/src/SolverDAB.py +++ b/src/SolverDAB.py @@ -24,8 +24,10 @@ import time from array import array from SolverBase import SolverBase +from ProblemCristina import ProblemCristina from ProblemFusion import ProblemFusion from ProblemNonSeparable import ProblemNonSeparable +from SolutionCristina import SolutionCristina from SolutionFusion import SolutionFusion from SolutionNonSeparable import SolutionNonSeparable import Utils as u @@ -85,6 +87,12 @@ def __init__(self, ProblemType, infile): self.__solution_type = u.solution_type.NONSEPARABLE self.__bestLocalSolution = SolutionNonSeparable(infile) self.__bestGlobalSolution = SolutionNonSeparable(infile) + elif ProblemType == u.problem_type.CRISTINA: + self.__problem = ProblemCristina() + self.__solution_type = u.solution_type.CRISTINA + self.__bestLocalSolution = SolutionCristina(infile) + self.__bestGlobalSolution = SolutionCristina(infile) + if u.objective == u.objectiveType.MAXIMIZE: self.__bestLocalSolution.setValue(-u.infinity) self.__bestGlobalSolution.setValue(-u.infinity) @@ -453,6 +461,10 @@ def __init__(self, problem_type, infile, configfile): self.__problem = ProblemNonSeparable() self.__bestSolution = SolutionNonSeparable(self.__infile) self.__bestGlobalSolution = SolutionNonSeparable(self.__infile) + elif self.__problem_type == u.problem_type.CRISTINA: + self.__problem = ProblemCristina() + self.__bestSolution = SolutionCristina(self.__infile) + self.__bestGlobalSolution = SolutionCristina(self.__infile) else: u.logger.critical("SolverDAB (" + str(sys.exc_info()[2].tb_lineno) + "). Unknown problem type " + str(problem_type)) @@ -491,6 +503,13 @@ def __init__(self, problem_type, infile, configfile): "pending.queue", u.solution_type.FUSION, infile, False) self.__topSolutions = solQueue.SolutionsQueue( "top.queue", u.solution_type.FUSION, infile, False, True) + if problem_type == u.problem_type.CRISTINA: + self.__finishedSolutions = solQueue.SolutionsQueue( + "finishedNonSep.queue", u.solution_type.CRISTINA, infile, True, True) + self.__pendingSolutions = solQueue.SolutionsQueue( + "pendingNonSep.queue", u.solution_type.CRISTINA, infile, False) + self.__topSolutions = solQueue.SolutionsQueue( + "top.queue", u.solution_type.CRISTINA, infile, False, True) if problem_type == u.problem_type.NONSEPARABLE: self.__finishedSolutions = solQueue.SolutionsQueue( "finishedNonSep.queue", u.solution_type.NONSEPARABLE, infile, True, True) @@ -747,6 +766,8 @@ def receiveSolutions(self): solutionTemp = SolutionFusion(self.__infile) elif self.__problem_type == u.problem_type.NONSEPARABLE: solutionTemp = SolutionNonSeparable(self.__infile) + elif self.__problem_type == u.problem_type.CRISTINA: + solutionTemp = SolutionCristina(self.__infile) if solutionTemp is None: u.logger.error("Solution is None after creation (type " + str(self.__problem_type) + ")") @@ -886,6 +907,8 @@ def runDistributed(self): self.__problem = ProblemFusion() elif (self.__problem_type == u.problem_type.NONSEPARABLE): self.__problem = ProblemNonSeparable() + elif (self.__problem_type == u.problem_type.CRISTINA): + self.__problem = ProblemCristina() numParams = self.__bestSolution.getNumberofParams() buff = array('f', [0]) * numParams diff --git a/src/Utils.py b/src/Utils.py index e8f3fa8..6df36a1 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -55,10 +55,10 @@ def enum(**enums): return type('Enum', (), enums) #problem type -problem_type = enum(NONE=0, FUSION=1, NONSEPARABLE=2) +problem_type = enum(NONE=0, FUSION=1, NONSEPARABLE=2, CRISTINA=3) #solution type -solution_type = enum(FUSION=1, NONSEPARABLE=2) +solution_type = enum(FUSION=1, NONSEPARABLE=2, CRISTINA=3) #solver type solver_type = enum(NONE=0, DAB=1, SA=2) diff --git a/src/Worker.py b/src/Worker.py index 4837035..0fe8cc4 100755 --- a/src/Worker.py +++ b/src/Worker.py @@ -24,8 +24,10 @@ import sys from mpi4py import MPI import Utils as u +from SolutionCristina import SolutionCristina from SolutionFusion import SolutionFusion from SolutionNonSeparable import SolutionNonSeparable +from ProblemCristina import ProblemCristina from ProblemFusion import ProblemFusion from ProblemNonSeparable import ProblemNonSeparable @@ -59,6 +61,8 @@ def __init__(self, comm, problem_type): self.__problem = ProblemFusion() elif self.__problem_type == u.problem_type.NONSEPARABLE: self.__problem = ProblemNonSeparable() + elif self.__problem_type == u.problem_type.CRISTINA: + self.__problem = ProblemCristina() except Exception as e: print("Worker " + str(sys.exc_info()[2].tb_lineno) + " " + str(e)) @@ -93,6 +97,8 @@ def run(self, infile, cfile): solution = SolutionFusion(infile) elif self.__problem_type == u.problem_type.NONSEPARABLE: solution = SolutionNonSeparable(infile) + elif self.__problem_type == u.problem_type.CRISTINA: + solution = SolutionCristina(infile) else: u.logger.error("WORKER (" + str(self.__rank) + ") Problem type not supported") diff --git a/src/disop.py b/src/disop.py index e9f03c8..c55e56f 100755 --- a/src/disop.py +++ b/src/disop.py @@ -101,7 +101,7 @@ def main(): try: inputfile = "../data/param_config.xml" configfile = "../data/DABConfigFile" - problem_type = util.problem_type.FUSION + problem_type = util.problem_type.CRISTINA solver_type = util.solver_type.DAB #process the arguments if the argparse module has been found @@ -112,7 +112,7 @@ def main(): parser.add_argument('-p', '--problem', required=True, type=str, default='FUSION', - choices=['FUSION', 'NONSEPARABLE'], + choices=['FUSION', 'NONSEPARABLE', 'CRISTINA'], help='Problem type') parser.add_argument('-v', '--verbose', required=False, type=int, default=3, choices=[1, 2, 3], @@ -135,6 +135,8 @@ def main(): #extract the problem type if args.problem == 'FUSION': problem_type = util.problem_type.FUSION + if args.problem == 'CRISTINA': + problem_type = util.problem_type.CRISTINA if args.problem == 'NONSEPARABLE': problem_type = util.problem_type.NONSEPARABLE