Exemplo n.º 1
0
        for i in camp_locations:
            camps += [locations[i]]
        camp_names = ["Mahama", "Nduta", "Nyarugusu", "Nakivale", "Lusenda"]

        refugees_in_camps_sim = 0
        for c in camps:
            refugees_in_camps_sim += c.numAgents

        # calculate errors
        for i in range(0, len(camp_locations)):
            camp_number = camp_locations[i]
            errors += [
                a.rel_error(locations[camp_number].numAgents, loc_data[i])
            ]
            abs_errors += [
                a.abs_error(locations[camp_number].numAgents, loc_data[i])
            ]

        output = "%s" % t

        for i in range(0, len(errors)):
            camp_number = camp_locations[i]
            output += ",%s,%s,%s" % (locations[camp_number].numAgents,
                                     loc_data[i], errors[i])

        if refugees_raw > 0:
            #output_string += ",%s,%s,%s,%s" % (float(np.sum(abs_errors))/float(refugees_raw), int(sum(loc_data)), e.numAgents(), refugees_raw)
            output += ",%s,%s,%s,%s,%s,%s" % (
                float(np.sum(abs_errors)) / float(refugees_raw),
                int(sum(loc_data)), e.numAgents(), refugees_raw,
                refugees_in_camps_sim, refugee_debt)
Exemplo n.º 2
0
    camps = []
    for i in camp_locations:
      camps += [lm[i]]
      loc_data += [d.get_field(i, t)]

    # calculate retrofitted time.
    refugees_in_camps_sim = 0
    for c in camps:
      refugees_in_camps_sim += c.numAgents

    # calculate errors
    j=0
    for i in camp_locations:
      errors += [a.rel_error(lm[i].numAgents, loc_data[j])]
      abs_errors += [a.abs_error(lm[i].numAgents, loc_data[j])]

      j += 1

    output = "%s" % t

    for i in range(0,len(errors)):
      output += ",%s,%s,%s" % (lm[camp_locations[i]].numAgents, loc_data[i], errors[i])

    if refugees_raw>0:
      output += ",%s,%s,%s,%s,%s,%s" % (float(np.sum(abs_errors))/float(refugees_raw), int(sum(loc_data)), e.numAgents(), refugees_raw, refugees_in_camps_sim, refugee_debt)
    else:
      output += ",0,0,0,0,0,0"

    print(output)
Exemplo n.º 3
0
def run_micro_macro_model(e, c, submodel, ig, d, camp_locations, end_time):
    # Set up a mechanism to incorporate temporary decreases in refugees
    refugee_debt = 0
    # raw (interpolated) data from TOTAL UNHCR refugee count only.
    refugees_raw = 0

    while c.reuse_coupling():
        for t in range(0, end_time):

            # if t>0:
            ig.AddNewConflictZones(e, t)

            # Determine number of new refugees to insert into the system.
            new_refs = d.get_daily_difference(
                t, FullInterpolation=True, SumFromCamps=False) - refugee_debt

            refugees_raw += d.get_daily_difference(t,
                                                   FullInterpolation=True,
                                                   SumFromCamps=False)

            if log_exchange_data is True:
                c.logNewAgents(t, new_refs)

            if new_refs < 0:
                refugee_debt = -new_refs
                new_refs = 0
            elif refugee_debt > 0:
                refugee_debt = 0

            # Insert refugee agents

            if submodel == "macro":
                print("t={}, inserting {} new agents".format(t, new_refs),
                      file=sys.stderr)
                # e.add_agents_to_conflict_zones(new_refs)
                for i in range(0, new_refs):
                    e.addAgent(e.pick_conflict_location())
                e.updateNumAgents(log=False)

            # e.printInfo()

            # exchange data with other code.
            # immediately after agent insertion to ensure ghost locations
            # work correctly.
            c.Couple(t)

            e.refresh_conflict_weights()
            t_data = t

            # e.enact_border_closures(t)
            e.evolve()

            # Calculation of error terms
            errors = []
            abs_errors = []
            loc_data = []

            camps = []

            for i in camp_locations:
                camps += [lm[i]]
                loc_data += [d.get_field(i, t)]

            # calculate retrofitted time.
            refugees_in_camps_sim = 0

            for camp in camps:
                refugees_in_camps_sim += camp.numAgents

            if e.getRankN(t):
                output = "{}".format(t)

                j = 0
                for i in camp_locations:
                    errors += [a.rel_error(lm[i].numAgents, loc_data[j])]
                    abs_errors += [a.abs_error(lm[i].numAgents, loc_data[j])]

                    j += 1

                output = "{}".format(t)

                for i in range(0, len(errors)):
                    output += ",{},{},{}".format(
                        lm[camp_locations[i]].numAgents, loc_data[i],
                        errors[i])

                if refugees_raw > 0:
                    output += ",{},{},{},{},{},{}".format(
                        round(
                            float(np.sum(abs_errors)) / float(refugees_raw),
                            a.ROUND_NDIGITS), int(sum(loc_data)),
                        e.numAgents(), refugees_raw, refugees_in_camps_sim,
                        refugee_debt)
                else:
                    output += ",0,0,0,0,0,0"

                # print(output)

                with open(out_csv_file, "a+") as f:
                    f.write(output)
                    f.write("\n")
                    f.flush()
                # exit()

        # break while-loop(c.reuse_coupling) if coupling_type == file
        if not hasattr(c, "instance"):
            break