Exemplo n.º 1
0
def hello(src_addr='127.0.0.1',
          src_port=6379,
          src_db=0,
          src_passwd='',
          dst_addr='127.0.0.1',
          dst_port=6379,
          dst_db=0,
          dst_passwd=''):
    src = instance.Instance(src_addr, src_port, src_db, src_passwd).connect()
    dst = instance.Instance(dst_addr, dst_port, dst_db, dst_passwd).connect()

    for key in src.keys():
        print(key)
        hash_keys = src.hkeys(key)
        for k in hash_keys:
            v = src.hget(key, k)
            dst.hset(key, k, v)
    print('Complete!')
Exemplo n.º 2
0
        def put(self, path):
            message = json.loads(self.request.body.decode("utf-8"))
            if path in instances:
                self.set_status(304, "instance already exists")
                self.finish()
                return

            instances[path] = instance.Instance(
                map_loader.get_map(message["map"]))
            instances[path].run_loop()

            self.set_status(201)
            self.finish()
Exemplo n.º 3
0
 def addInstance(self, name, functionName):
     """Add an instance with a name and function name to the top-level
        network."""
     name = keywords.fixID(name)
     functionName = keywords.fixID(functionName)
     with self.updateLock:
         func = self.imports.getFunctionByFullName(functionName,
                                                   self.topLevelImport)
         (net, instanceName) = self.network.getContainingNetwork(name)
         nm = ""
         if net.inActiveInstance is not None:
             nm = net.inActiveInstance.getCanonicalName()
         #log.debug("net=%s, instanceName=%s"%(nm, instanceName))
         inst = instance.Instance(instanceName, func, functionName)
         net.addInstance(inst)
Exemplo n.º 4
0
def _PP_instance(s, pnp, chunk, pp=None):
    """ Create an Instance object with a lookup string for the PP-attacher TiMBL server.
        If the chunk is a NP inside a PNP, you must supply the PP preceding it.
    """
    lemma = lambda i: s.lemmata[i] or s.words[
        i]  # Prefer lemmata, use words if unavailable.
    p0 = pp and lemma(
        pp.start) or '-'  # The PP as lemma, if given, '-' otherwise.
    p1 = lemma((pp or chunk).head.index)  # The head of the chunk as lemma.
    p2 = s.pos[(
        pp
        or chunk).head.index]  # The head of the chunk as part-of-speech tag.
    p3 = pnp.start != 0 and lemma(
        pnp.start - 1) or '-'  # The lemma of the word before the PP.
    p4 = pnp.start != 0 and s.pos[
        pnp.start -
        1] or '-'  # The part-of-speech tag of the word before the PP.
    p5 = lemma(pnp.start)  # The preposition word of the PNP as lemma.
    p6 = lemma(pnp.head.index)  # The head of the PNP as lemma.
    p7 = s.pos[pnp.head.index]  # The head of the PNP as part-of-speech tag.
    p8 = _count_NP(
        s, chunk.start,
        pnp.start)  # The number of NPs between the chunk and the PNP.
    p9 = _count_PNP(
        s, chunk.start,
        pnp.start)  # The number of PNPs between the chunk and the PNP.
    if pnp.start > chunk.start:
        # The number of commas and other punctuation between the chunk and the PNP.
        # The distance between chunk and pnp (add one so it is never zero).
        comma, other, n = _count_punctuation(s,
                                             chunk.stop - 1,
                                             pnp.start,
                                             selection=[u','])
        distance = pnp.start - (pp or chunk).stop + 1
    else:
        comma, other, n = _count_punctuation(s,
                                             pnp.stop - 1,
                                             chunk.start,
                                             selection=[u','])
        distance = -1 * ((pp or chunk).start - pnp.stop + 1)
    if pp and distance < 0:
        return None
    # Create the instance.
    format = u'%d %d %d %s %s %s %s %s %s %s %s %d %d'
    format = format % (comma, other, distance, p0, p1, p2, p3, p4, p5, p6, p7,
                       p8, p9)
    return instance.Instance(format, chunk.head.index, pnp.start, chunk.type)
Exemplo n.º 5
0
import time
import pymzn
import numpy as np
import pymzn.config
import instance

#pymzn.debug()
problem = instance.Instance()

problem.set_args(10, 10, 100, 10, 10, 5, 20)
sol = pymzn.ORTools()

r_range = [20, 30, 40, 50]

pymzn.config.set('mzn2fzn', '/home/andrea/MiniZincIDE/mzn2fzn')
pymzn.config.set('solns2out', '/home/andrea/MiniZincIDE/solns2out')

output_name = "./Gurobi.csv"

res = np.zeros((4, 5, 3))

seeds = [1234, 1989,
         290889]  #, 251091, 240664, 190364, 120863, 101295, 31089, 3573113]
s_time = time.time()

for r in range(0, len(r_range)):
    problem.set_r0(r_range[r])
    for i in range(0, len(seeds)):
        problem.arcs_creator(seeds[i])
        name = "./data/data_" + str(i) + ".dzn"
        problem.write_dzn_file(name)
Exemplo n.º 6
0
outputFolder = currentFolder + "/data/"   #folder that contains output.json
outputFileName = "shuttlemile_1_0_transf_3_alpha_0_05_multipl_1_0_busfreqs_2_3_4_sample_output.json"
roadTravelTimesFileName = "duration_matrix_jan1_oct31.csv"
roadTravelDistancesFileName = "distance_matrix_jan1_oct31.csv"
odPairsFileName = "sample_n_33000_odx.csv"

# Set parameters
param = dict()
param['outputFile'] = outputFolder + outputFileName
param['roadTravelTimesFile'] = dataFolder + roadTravelTimesFileName
param['travelTimeFactorShuttle'] = 1
param['travelTimeFactorBus'] = 1
param['roadTravelDistancesFile'] = dataFolder + roadTravelDistancesFileName

# Create a network design instance and load the existing output file
inst = instance.Instance(runFile=None, parameters=param, logFile=None)
inst.load_outputFile()

# Replace the trips that were used to create the design by other od pairs
# Paths are calculated with the trip splitting information in the instance
#inst.replace_trips_by_sample(dataFolder + odPairsFileName)
output = inst.output

# Output['trips'] now contains trip information
# Next, isolate shuttle legs

# Add start_times and end_times to trip legs
for trip in output['trips']:
    times = [time for time in pd.to_datetime(trip['departure_times'])]

    for leg in trip['legs']:
Exemplo n.º 7
0
def main():
    filename = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            "data_in/test_1.txt")
    inst = instance.Instance(filename)

    # input from master problem, now random
    id_profile = 0
    random.seed(42)
    rewards = [random.randint(0, 30000) for i in range(inst.J)]
    #rewards = [random.uniform(0.0, 30000.0) for i in range(inst.J)]
    equivalences = [[0, 1], [2, 3]]
    mutexes = [[2, 1], [4, 3]]
    # input from master problem, now random

    types = inst.profiles[id_profile]
    types.insert(0, inst.INIT)
    types.append(inst.TERM)
    trans_cost = [[0 for i in range(inst.V)] for j in range(inst.V)]
    trans_time = [[0 for i in range(inst.V)] for j in range(inst.V)]
    for i in range(len(inst.edges)):
        for j in range(len(inst.edges[i])):
            trans_cost[i][inst.edges[i][j][
                'to']] = inst.edges[i][j]['C'] * inst.edges[i][j]['t']
            trans_time[i][inst.edges[i][j]['to']] = inst.edges[i][j]['t']
    changeover_cost = 0
    for i in range(1, len(types)):
        changeover_cost += trans_cost[types[i - 1]][types[i]]

    cp = CpoModel()
    primitives = [[] for i in range(inst.J)]
    all_primitives = []
    init = cp.interval_var(start=0)
    init.set_end_max(inst.L)
    total_cost = changeover_cost + inst.vertices[
        inst.INIT]['C'] * cp.length_of(init, 0)
    modes_of_mach = [init
                     ]  # serves only for retrieving starts and ends of modes
    last_shift = init
    for i in range(1, len(types) - 1):
        v = types[i]
        shift = cp.interval_var()
        shift.set_size_min(inst.vertices[v]['t_min'])
        shift.set_size_max(inst.vertices[v]['t_max'])
        shift.set_end_max(inst.L)
        total_cost += inst.vertices[v]['C'] * cp.length_of(shift, 0)
        cp.add(
            cp.start_at_end(shift, last_shift,
                            -trans_time[types[i - 1]][types[i]]))
        last_shift = shift
        modes_of_mach.append(shift)
        for t in range(inst.J):
            if inst.tasks[t]['p'][v] <= inst.L:
                prim = cp.interval_var(size=inst.tasks[t]['p'][v])
                total_cost -= rewards[t] * cp.presence_of(prim)
                prim.set_optional()
                prim.set_start_min(inst.tasks[t]['r'])
                prim.set_end_max(inst.tasks[t]['d'])
                primitives[t].append(prim)
                all_primitives.append(prim)
                cp.add(cp.start_before_start(shift, prim))
                cp.add(cp.end_before_end(prim, shift))
    term = cp.interval_var(end=inst.L)
    total_cost += inst.vertices[inst.TERM]['C'] * cp.length_of(term, 0)
    cp.add(
        cp.start_at_end(term, last_shift,
                        -trans_time[types[len(types) - 2]][inst.TERM]))
    modes_of_mach.append(term)
    cp.add(cp.no_overlap(cp.sequence_var(all_primitives)))
    for t in range(inst.J):
        cp.add(sum([cp.presence_of(p) for p in primitives[t]]) <= 1)
    for eq in equivalences:
        cp.add(
            sum([cp.presence_of(p) for p in primitives[eq[0]]]) == sum(
                [cp.presence_of(p) for p in primitives[eq[1]]]))
    for mut in mutexes:
        cp.add(
            sum([cp.presence_of(p) for p in primitives[mut[0]]]) +
            sum([cp.presence_of(p) for p in primitives[mut[1]]]) <= 1)
    cp.add(cp.minimize(total_cost))

    # set TimeLimit in seconds or delete it for no limit
    # parameters DefaultInferenceLevel and Workers may be beneficial to add
    sol = cp.solve(
        TimeLimit=30,
        LogVerbosity="Quiet")  #, DefaultInferenceLevel='Extended', Workers=1)
    if sol:
        tasks = []
        for t in range(inst.J):
            for pr in primitives[t]:
                p = sol.get_var_solution(pr)
                if p.is_present():
                    tasks.append({
                        "task": t,
                        "start": p.get_start(),
                        "end": p.get_end()
                    })
                    break
        modes = []
        sched_cost = 0
        for t in range(len(modes_of_mach)):
            m = sol.get_var_solution(modes_of_mach[t])
            modes.append({
                "mode": types[t],
                "start": m.get_start(),
                "end": m.get_end()
            })
            sched_cost += inst.vertices[types[t]]['C'] * m.get_length()
        print("Solution status: " + sol.get_solve_status())
        print("Solve time: " + str(sol.get_solve_time()))
        print("Objective: " + str(sol.get_objective_values()[0]))
        print("Schedule cost: " + str(sched_cost))
        print(tasks)
        print(modes)
    else:
        print("No solution found.")
Exemplo n.º 8
0
def genTest(nodes, alpha=1, m=1, q=math.inf):
    nodes = list(map(lambda i: point.Point(*i), nodes))
    v0 = nodes.pop(-1)
    u = nodes[:math.floor(alpha * len(nodes))]
    w = nodes[math.floor(alpha * len(nodes)):]
    return inst.Instance(v0, u, w, m, q)
Exemplo n.º 9
0
 def createInstance(self, conn):
     return instance.Instance(self, conn)
Exemplo n.º 10
0
    exp_param = dict(zip(vary_param.keys(), value))

    experiment['string'] = dict_str(exp_param)
    experiment['log'] = outputFolder + experiment['string'] + "_log.txt"
    experiment['param'] = copy.deepcopy(fixed_param)
    experiment['param'].update(exp_param)
    experiment['param'][
        'outputFile'] = outputFolder + experiment['string'] + "_output.json"

    experiments.append(experiment)

for experiment in experiments:

    # Run the experiments and save output and log to disk
    inst = instance.Instance(runFile, experiment['param'], experiment['log'])
    inst.run()

    # Verify correctness
    inst.verifyOutput(
    )  #See Instance.verifyOutput() in instance.py for possible options

# Create maps and histograms
for experiment in experiments:
    inst = instance.Instance(runFile, experiment['param'], experiment['log'])
    inst.load_outputFile()

    htmlFile = outputFolder + experiment['string'] + "_design.html"
    pngFile = outputFolder + experiment['string'] + "_design.png"
    inst.createPlot()
    inst.exportPlot(htmlFile, pngFile)
Exemplo n.º 11
0
def preprocessInstance(inputList):
    inst = instance.Instance(inputList)
    inst.process()
    return inst
Exemplo n.º 12
0
 def run(self, outf=None):
     """Do a transaction."""
     # we start out with 'none' objects, and initialize them to sets if
     # there's a need for it.
     locked = False
     addedInstances = None
     affectedOutputAIs = None
     affectedInputAIs = None
     # check for errors
     if (self.errMsg is not None):
         if self.activeInstance is not None:
             self.activeInstance.markError(self.errMsg)
             # and bail out immediately
             return
     try:
         #log.debug("TRANSACTION STARTING *****************")
         if (self.newConnections is None and self.setValues is None):
             # In this case, there is only one active instance to lock
             pass
         else:
             # there are multiple updates, so we must lock a network lock
             self.project.updateLock.acquire()
             # these are the active instances for which output locks are set
             affectedOutputAIs = set()
             # these are active instances for which handleNewInput() is
             # called
             affectedInputAIs = set()
             if self.activeInstance is not None:
                 affectedOutputAIs.add(self.activeInstance)
         # now make the new instances
         if self.newInstances is not None:
             addedInstances = []
             for newInstance in self.newInstances:
                 log.debug("Making new instance %s of fn %s" %
                           (newInstance.name, newInstance.functionName))
                 fn = self.project.imports.getFunctionByFullName(
                     newInstance.functionName, self.lib)
                 inst = instance.Instance(newInstance.name, fn,
                                          fn.getFullName())
                 # for later activation
                 addedInstances.append(self.activeNetwork.addInstance(inst))
         # make the new connections
         if self.newConnections is not None:
             # Make the connections
             for newConnection in self.newConnections:
                 if newConnection.conn is None:
                     self._makeConn(newConnection)
                 self.activeNetwork.findConnectionSrcDest(
                     newConnection.conn, affectedInputAIs,
                     affectedOutputAIs)
         if self.setValues is not None:
             for val in self.setValues:
                 log.debug("Setting new value %s" % (val.itemName))
                 val.findAffected(affectedOutputAIs, affectedInputAIs)
         if affectedOutputAIs is None:
             if self.activeInstance is not None:
                 self.activeInstance.outputLock.acquire()
                 locked = True
         else:
             for ai in affectedOutputAIs:
                 ai.outputLock.acquire()
             locked = True
             log.debug("Locked.")
         # now do the transaction
         # new values
         if self.setValues is not None:
             for val in self.setValues:
                 if outf is not None:
                     val.describe(outf)
                 val.set(self.project, self)
         # connections
         if self.newConnections is not None:
             for newConnection in self.newConnections:
                 if outf is not None:
                     newConnection.describe(outf)
                 self.activeNetwork.addConnection(newConnection.conn, self)
         # call the function meant specifically for this
         if self.activeInstance is not None:
             if outf is not None:
                 if self.outputs is not None:
                     for output in self.outputs:
                         output.describe(outf)
                 if self.subnetOutputs is not None:
                     for output in self.subnetOutputs:
                         output.describe(outf)
             if len(self.outputs) > 0 or len(self.subnetOutputs) > 0:
                 self.activeInstance.handleTaskOutput(
                     self, self.seqNr, self.outputs, self.subnetOutputs,
                     self.warnMsg)
         if affectedInputAIs is not None:
             for ai in affectedInputAIs:
                 #log.debug("affected input AI %s"%ai.getCanonicalName())
                 ai.handleNewInput(self, self.seqNr)
     except:
         fo = StringIO()
         traceback.print_exception(sys.exc_info()[0],
                                   sys.exc_info()[1],
                                   sys.exc_info()[2],
                                   file=fo)
         errmsg = "Transaction error: %s" % (fo.getvalue())
         if self.activeInstance is not None:
             self.activeInstance.markError(errmsg)
         else:
             log.error(errmsg)
     finally:
         if locked:
             if affectedOutputAIs is None:
                 self.activeInstance.outputLock.release()
             else:
                 for ai in affectedOutputAIs:
                     ai.outputLock.release()
         #if affectedOutputAIs is not None:
         if not (self.newConnections is None and self.setValues is None):
             self.project.updateLock.release()
     log.debug("Finished transaction locks")
     if addedInstances is not None:
         for inst in addedInstances:
             inst.activate()
Exemplo n.º 13
0
    def startElement(self, name, attrs):
        # first handle all the sub-readers
        if self.cmdReader is not None:
            self.cmdReader.startElement(name, attrs)
        elif self.fnInputReader is not None:
            self.fnInputReader.startElement(name, attrs)
        elif self.valueReader is not None:
            self.valueReader.startElement(name, attrs)
        elif self.descReader is not None:
            self.descReader.startElement(name, attrs)
        # and then actual elements
        elif name == "cpc":
            # top-level element
            if attrs.has_key('version'):
                self.fileVersion = int(attrs.getValue("version"))
            else:
                self.fileVersion = 0
            if self.fileVersion > curVersion:
                raise ProjectXMLError("Can't read file from the future.")
        elif name == "import":
            if not attrs.has_key('name'):
                raise ProjectXMLError("import has no name", self)
            name = keywords.fixID(attrs.getValue('name'))
            nimport = self.importList.get(name)
            if nimport is None:
                # we don't have it yet. Read it.
                nimport = self.project.importName(name)
                # and try again
                nimport = self.importList.get(name)
                if nimport is None:
                    raise ProjectXMLError("Failed to import %s" % name, self)
            self.localImports[name] = nimport
        elif name == "function":
            if self.function is not None:
                raise ProjectXMLError(
                    "function-in-function definitions not supported", self)
            if not attrs.has_key("type"):
                raise ProjectXMLError("function has no type", self)
            if not attrs.has_key("id"):
                raise ProjectXMLError("function has no id", self)
            fntype = attrs.getValue("type")
            id = keywords.fixID(attrs.getValue("id"))
            if fntype == "python":
                tsk = atomic.SimpleFunctionFunction(id, lib=self.thisImport)
            elif fntype == "python-extended":
                tsk = atomic.ExtendedFunctionFunction(id, lib=self.thisImport)
            elif fntype == "network":
                tsk = network_function.NetworkFunction(id, lib=self.thisImport)
            elif fntype == "external":
                if self.dirName is None:
                    raise ProjectXMLError(
                        "external function without directory", self)
                tsk = external.ExternalFunction(id,
                                                basedir=self.dirName,
                                                lib=self.thisImport)
            else:
                raise ProjectXMLError(
                    "function type '%s' not recognized" % (fntype), self)
            self.function = tsk
            self.functionType = fntype
        elif name == "type":
            if self.function is not None:
                raise ProjectXMLError(
                    "type-in-function definitions not supported", self)
            if self.type is not None:
                raise ProjectXMLError("type-in-type definitions not supported",
                                      self)
            if not attrs.has_key("id"):
                raise ProjectXMLError("type has no id", self)
            if not attrs.has_key("base"):
                raise ProjectXMLError("type has no base", self)
            name = keywords.fixID(attrs.getValue("id"))
            basetype = self.importList.getTypeByFullName(
                attrs.getValue("base"), self.thisImport)
            self.type = basetype.inherit(name, self.thisImport)
            self.typeStack.append((self.type, None))
            if basetype.isSubtype(vtype.arrayType):
                if attrs.has_key("member-type"):
                    tnm = keywords.fixID(attrs.getValue("member-type"))
                    members = self.importList.getTypeByFullName(
                        tnm, self.thisImport)
                    self.type.setMembers(members)
                    log.debug("new array(%s) type %s" % (members.name, name))
                #else:
                #    raise ProjectXMLError("Array type %s has no member type"%
                #                          name, self)
            elif basetype.isSubtype(vtype.dictType):
                if attrs.has_key("member-type"):
                    tnm = keywords.fixID(attrs.getValue("member-type"))
                    members = self.importList.getTypeByFullName(
                        tnm, self.thisImport)
                    self.type.setMembers(members)
                    log.debug("new dict(%s) type %s" % (members.name, name))
            elif basetype.isSubtype(vtype.fileType):
                if attrs.has_key("extension"):
                    self.type.setExtension(attrs.getValue("extension"))
                if attrs.has_key("mime-type"):
                    self.type.setExtension(attrs.getValue("mime-type"))
        elif name == "inputs":
            if self.type is not None:
                raise ProjectXMLError("nested inputs", self)
            self.ioitem = "inputs"
            if self.instance is not None:
                self.type = self.instance.getInputs()
                self.typeStack.append((self.type, None))
            elif self.function is not None:
                self.type = self.function.getInputs()
                self.typeStack.append((self.type, None))
            elif self.activeInst is not None:
                curValue = self.activeInst.getStagedInputs()
                self.affectedInputAIs.add(self.activeInst)
                self.setValueReader(
                    value.ValueReader(self.filename,
                                      curValue,
                                      importList=self.importList,
                                      currentImport=self.thisImport,
                                      sourceTag=self), name)
            else:
                raise ProjectXMLError("inputs without function/instance", self)
        elif name == "outputs":
            if self.type is not None:
                raise ProjectXMLError("nested outputs", self)
            self.ioitem = "outputs"
            if self.instance is not None:
                self.type = self.instance.getOutputs()
                self.typeStack.append((self.type, None))
            elif self.function is not None:
                self.type = self.function.getOutputs()
                self.typeStack.append((self.type, None))
            elif self.activeInst is not None:
                curValue = self.activeInst.getOutputs()
                self.affectedOutputAIs.add(self.activeInst)
                self.setValueReader(
                    value.ValueReader(self.filename,
                                      curValue,
                                      importList=self.importList,
                                      currentImport=self.thisImport,
                                      sourceTag=self), name)
            else:
                raise ProjectXMLError("outputs without function/instance",
                                      self)
        elif name == "subnet-inputs":
            if self.type is not None:
                raise ProjectXMLError("nested subnet-inputs", self)
            self.ioitem = "subnet-inputs"
            if self.instance is not None:
                self.type = self.instance.getSubnetInputs()
                self.typeStack.append((self.type, None))
            elif self.function is not None:
                self.type = self.function.getSubnetInputs()
                self.typeStack.append((self.type, None))
            elif self.activeInst is not None:
                curValue = self.activeInst.getStagedSubnetInputs()
                self.affectedInputAIs.add(self.activeInst)
                self.setValueReader(
                    value.ValueReader(self.filename,
                                      curValue,
                                      importList=self.importList,
                                      currentImport=self.thisImport,
                                      sourceTag=self), name)
            else:
                raise ProjectXMLError(
                    "subnet-inputs without function/instance", self)
        elif name == "subnet-outputs":
            if self.type is not None:
                raise ProjectXMLError("nested subnet-outputs", self)
            self.ioitem = "subnet-outputs"
            if self.instance is not None:
                self.type = self.instance.getSubnetOutputs()
                self.typeStack.append((self.type, None))
            elif self.function is not None:
                self.type = self.function.getSubnetOutputs()
                self.typeStack.append((self.type, None))
            elif self.activeInst is not None:
                curValue = self.activeInst.getSubnetOutputs()
                self.affectedOutputAIs.add(self.activeInst)
                self.setValueReader(
                    value.ValueReader(self.filename,
                                      curValue,
                                      importList=self.importList,
                                      currentImport=self.thisImport,
                                      sourceTag=self), name)
            else:
                raise ProjectXMLError(
                    "subnet-outputs without function/instance", self)
        elif name == "field":
            if self.type is None and self.ioitem is None:
                raise ProjectXMLError("Field without type context", self)
            if not attrs.has_key("type"):
                raise ProjectXMLError("No type in field", self)
            tpnm = keywords.fixID(attrs.getValue("type"))
            if self.type is not None and self.type.isCompound():
                tp = self.importList.getTypeByFullName(tpnm, self.thisImport)
                nm = None
                if self.type.isSubtype(vtype.arrayType):
                    self.type.setMembers(tp)
                elif self.type.isSubtype(vtype.dictType):
                    self.type.setMembers(tp)
                elif self.type.isSubtype(vtype.recordType):
                    if not attrs.has_key("id"):
                        raise ProjectXMLError("No id in list field", self)
                    const = cpc.util.getBooleanAttribute(attrs, "const")
                    opt = cpc.util.getBooleanAttribute(attrs, "opt")
                    complete = cpc.util.getBooleanAttribute(attrs, "complete")
                    nm = keywords.fixID(attrs.getValue("id"))
                    self.type.addMember(nm, tp, opt, const, complete)
                # add it to the stack
                self.type = tp
                self.typeStack.append((tp, nm))
            else:
                raise ProjectXMLError(
                    "Non-compound type %s can't have fields" %
                    self.type.getName(), self)
        elif name == "network":
            #if len(self.networkStack) < 1:
            #    raise ProjectXMLError("network in network definition", self)
            if self.function is None:
                # there is no function, check whether we're in an active
                # network:
                if len(self.activeInstStack) < 1:
                    # we're not. Get the top level
                    if len(self.networkStack) > 0:
                        raise ProjectXMLError("network in network definition",
                                              self)
                    self.networkStack.append(self.thisImport.getNetwork())
                else:
                    self.networkStack.append(self.activeInst.getNet())
            else:
                # this is a function network
                if len(self.networkStack) > 0:
                    raise ProjectXMLError("network in network definition",
                                          self)
                self.networkStack.append(self.function.getSubnet())
            self.network = self.networkStack[-1]
        elif name == "instance":
            if self.network is None:
                raise ProjectXMLError("instance without network", self)
            if not attrs.has_key("id"):
                raise ProjectXMLError("instance has no id", self)
            if not attrs.has_key("function"):
                raise ProjectXMLError("instance has no function", self)
            id = keywords.fixID(attrs.getValue("id"))
            fn = keywords.fixID(attrs.getValue('function'))
            func = self.importList.getFunctionByFullName(fn, self.thisImport)
            self.instance = instance.Instance(id, func, fn, self.thisImport)
        elif name == "assign":
            if not 'value' in attrs:
                raise ProjectXMLError("assign has no value", self)
            if not attrs.has_key('type'):
                raise ProjectXMLError("assign has no type", self)
            if not attrs.has_key('dest'):
                raise ProjectXMLError("assign has no destination", self)
            valueString = attrs.getValue('value')
            typestr = keywords.fixID(attrs.getValue('type'))
            dst = keywords.fixID(attrs.getValue('dest'))
            # get the type object
            tp = self.importList.getTypeByFullName(typestr, self.thisImport)
            # get the value from the type object
            val = active_value.ActiveValue(
                value.interpretLiteral(valueString, tp), tp)
            val.setUpdated(True)
            #log.debug("value is %s, %s"%(str(val), valueString))
            # get the destination
            dstInstName, dstDir, dstItemName = (connection.splitIOName(
                dst, keywords.In))
            cn = connection.makeInitialValue(self.network, dstInstName, dstDir,
                                             dstItemName, val)
            self.network.findConnectionSrcDest(cn, self.affectedInputAIs,
                                               self.affectedOutputAIs)
            self.network.addConnection(cn, self)
        elif name == "connection":
            if self.network is None:
                raise ProjectXMLError("connection without network", self)
            if not attrs.has_key('src') and not attrs.has_key('value'):
                raise ProjectXMLError("connection has no source", self)
            if not attrs.has_key('dest'):
                raise ProjectXMLError("connection has no destination", self)

            dst = keywords.fixID(attrs.getValue('dest'))
            dstInstName, dstDir, dstItemName = (connection.splitIOName(
                dst, None))
            if attrs.has_key('src'):
                src = keywords.fixID(attrs.getValue('src'))
                # now check the source
                srcInstName, srcDir, srcItemName = (connection.splitIOName(
                    src, None))
                cn = connection.makeConnection(self.network, srcInstName,
                                               srcDir, srcItemName,
                                               dstInstName, dstDir,
                                               dstItemName)

            else:
                if not attrs.has_key("type"):
                    raise ProjectXMLError("connection has no type", self)
                typestr = keywords.fixID(attrs.getValue('type'))
                valueString = attrs.getValue('value')
                tp = self.importList.getTypeByFullName(typestr,
                                                       self.thisImport)
                # get the value from the type object
                val = value.interpretLiteral(valueString, tp)
                cn = connection.makeInitialValue(self.network, dstInstName,
                                                 dstDir, dstItemName, val)

            self.network.findConnectionSrcDest(cn, self.affectedInputAIs,
                                               self.affectedOutputAIs)
            self.network.addConnection(cn, self)
        elif name == "controller":
            # generic items
            if cpc.util.getBooleanAttribute(attrs, "persistent_dir"):
                # a persistent scratch dir is needed
                log.debug("Setting persistent dir for %s" %
                          self.function.getName())
                self.function.setPersistentDir(True)
            if cpc.util.getBooleanAttribute(attrs, "output_dir"):
                log.debug("Setting output dir always on for %s" %
                          self.function.getName())
                # a run dir is needed even if there's no file output
                self.function.setOutputDirWithoutFiles(True)
            if cpc.util.getBooleanAttribute(attrs, "log"):
                log.debug("Turning on logging for %s" %
                          (self.function.getName()))
                self.function.setLog(True)
            if cpc.util.getBooleanAttribute(attrs, "access_outputs"):
                log.debug("Controller uses current outputs for %s" %
                          (self.function.getName()))
                self.function.setAccessOutputs(True)
            if cpc.util.getBooleanAttribute(attrs, "access_subnet_outputs"):
                log.debug("Controller uses current subnet outputs for %s" %
                          (self.function.getName()))
                self.function.setAccessSubnetOutputs(True)
            # type-specific items
            if (self.functionType == "python"
                    or self.functionType == "python-extended"):
                importName = None
                if attrs.has_key("import"):
                    importName = keywords.fixID(attrs.getValue('import'))
                if not attrs.has_key('function'):
                    raise ProjectXMLError("python controller has no function",
                                          self)
                fnName = keywords.fixID(attrs.getValue("function"))
                self.function.setFunction(fnName, importName)
            elif self.functionType == "command":
                pass
            elif self.functionType == "external":
                if not attrs.has_key('executable'):
                    raise ProjectXMLError(
                        "command controller has no executable", self)
                executable = attrs.getValue("executable")
                self.function.setExecutable(executable)
                self.inController = True
        elif name == "stdin":
            if self.inController and self.functionType == "command":
                if not attrs.has_key('value'):
                    raise ProjectXMLError("stdin has no value", self)
                self.function.setStdin(attrs.getValue('value'))
            else:
                raise ProjectXMLError("stdin tag, without command controller",
                                      self)
        elif name == "arg":
            if self.inController and self.functionType == "command":
                pass
            else:
                raise ProjectXMLError("arg tag, without command controller",
                                      self)
        elif name == "active":
            # read in a description of an active network + active instances
            if not isinstance(self.network, active_network.ActiveNetwork):
                raise ProjectXMLError("active instance without active network",
                                      self)
            if not attrs.has_key("id"):
                raise ProjectXMLError("active instance has no id", self)
            if not attrs.has_key("state"):
                raise ProjectXMLError("active instance has no state", self)
            if not attrs.has_key("seqnr"):
                raise ProjectXMLError("active instance has no seqnr", self)
            name = keywords.fixID(attrs.getValue("id"))
            stStr = attrs.getValue("state")
            # now get the actual state
            state = None
            for st in active_inst.ActiveInstance.states:
                if st.str == stStr:
                    state = st
            if state is None:
                raise ProjectXMLError(
                    "active instance state %s invalid" % stStr, self)
            seqnr = int(attrs.getValue("seqnr"))
            ai = self.network.getActiveInstance(name)
            ai.setState(state)
            ai.setSeqNr(seqnr)
            if attrs.has_key('errmsg'):
                ai.markError(
                    xml.sax.saxutils.unescape(attrs.getValue('errmsg')), False)
            if attrs.has_key('warnmsg'):
                ai.setWarning(
                    xml.sax.saxutils.unescape(attrs.getValue('warnmsg')))
            if attrs.has_key('cputime'):
                try:
                    ai.setCputime(float(attrs.getValue('cputime')))
                except ValueError:
                    pass
            self.activeInstStack.append(ai)
            self.activeInst = ai
            self.affectedInputAIs.add(ai)
            self.affectedOutputAIs.add(ai)
        elif name == "active-connection":
            # any value associated with active connection points
            if self.activeInst is None:
                raise ProjectXMLError(
                    "active connection without active instance", self)
            if not attrs.has_key("id"):
                raise ProjectXMLError("active conn field has no id", self)
            if not attrs.has_key("type"):
                raise ProjectXMLError("active conn field has no type", self)
            tpnm = keywords.fixID(attrs.getValue("type"))
            tp = self.importList.getTypeByFullName(tpnm, self.thisImport)
            if attrs.has_key("seqnr"):
                seqnr = int(attrs.getValue("seqnr"))
            else:
                seqnr = 0
            name = keywords.fixID(attrs.getValue("id"))
            # TODO fix this for new type struct.
            val = None
            if attrs.has_key("value"):
                if not attrs.has_key("value_type"):
                    raise ProjectXMLError(
                        "active connection value without value_type", self)
                vtpnm = keywords.fixID(attrs.getValue("value_type"))
                vtp = self.importList.getTypeByFullName(vtpnm, self.thisImport)
                valnm = attrs.getValue("value")
                valueString = attrs.getValue('value')
                val = value.interpretLiteral(valueString, tp)
            if self.ioitem == "inputs":
                self.activeInst.setInput(name, tp, val, seqnr)
            elif self.ioitem == "outputs":
                self.activeInst.setOutput(name, tp, val, seqnr)
            elif self.ioitem == "subnet-inputs":
                self.activeInst.setSubnetInput(name, tp, val, seqnr)
            elif self.ioitem == "subnet-outputs":
                self.activeInst.setSubnetOutput(name, tp, val, seqnr)
            else:
                raise ProjectXMLError(
                    "unknown active connection ioitem '%s'" % (self.ioitem),
                    self)
        elif name == "tasks":
            pass  # just ignore it; we deal with tasks when they come
        elif name == "task":
            if self.curTask is not None:
                raise ProjectXMLError("task within task", self)
            if self.activeInst is None:
                raise ProjectXMLError("task without active instance", self)
            if not attrs.has_key("seqnr"):
                raise ProjectXMLError("task has no seqnr", self)
            if not attrs.has_key("priority"):
                raise ProjectXMLError("task has no priority", self)
            priority = int(attrs.getValue("priority"))
            seqnr = int(attrs.getValue("seqnr"))
            self.curTask = task.Task(self.project, self.activeInst,
                                     self.activeInst.getFunction(), None,
                                     priority, seqnr)
        elif name == "function-input":
            if self.curTask is None:
                raise ProjectXMLError("function-input without task", self)
            inp = run.FunctionRunInput()
            self.setFnInputReader(run.IOReader(inp, None), name)
            self.fnInputReader.setReportFilename(self.filename)
            self.fnInputReader.startElement(name, attrs)
        elif name == "command-list":
            if self.curTask is None:
                raise ProjectXMLError("commands without task", self)
            self.cmdReader = cpc.command.CommandReader()
        elif name == "desc":
            # A description. First find out what it describes.
            if self.type is not None:
                if (len(self.typeStack) > 1
                        and self.typeStack[-2][0].isSubtype(vtype.recordType)):
                    # if it is a field, describe it as a field
                    tp = self.typeStack[-2][0]
                    field = self.typeStack[-1][1]
                    lstm = tp.getRecordMember(field)
                    self.setDescReader(
                        description.DescriptionReader(lstm, self.filename),
                        name)
                elif not self.type.isBuiltin() and len(self.typeStack) == 1:
                    # it is a custom, describable type
                    self.setDescReader(
                        description.DescriptionReader(self.type,
                                                      self.filename), name)
                else:
                    raise ProjectXMLError("description of a builtin type.",
                                          self)
            elif self.function is not None:
                self.setDescReader(
                    description.DescriptionReader(self.function,
                                                  self.filename), name)
            elif self.curTask is None and self.network is None:
                self.setDescReader(
                    description.DescriptionReader(self.thisImport,
                                                  self.filename), name)
            # raise ProjectXMLError("Unknown item to describe.")

        else:
            raise ProjectXMLError("Unknown tag %s" % name, self)