예제 #1
0
def plot_data_gen(filename):
    _text = ""
    cxgs = ["cxg_4/"]
    for cxg_select in cxgs:
        ewfix = "sameseed/ew/" + cxg_select
        infile = filename

        mysas = SAS()
        mysas.import_states(ewfix + infile)

        pairs = []  # type: List[Tuple[CBSD, CBSD]]
        all_cbsds = mysas.CBSDs.copy()
        while len(all_cbsds) >= 2:
            i = all_cbsds.pop()
            for j in all_cbsds:
                if i.CxG != j.CxG:
                    pairs.append((i, j))
        keyset = [frozenset((pair[0].id, pair[1].id)) for pair in pairs]

        for et in [0.1, 0.5, 0.9]:
            num_ew_intercxg = len(
                [1 for key, val in mysas.ew_table.items() if key in keyset])
            num_edge_intercxg = len([
                1 for key, val in mysas.ew_table.items()
                if key in keyset and val > et
            ])
            num_potential_ix_intercxg = len([
                1 for key, val in mysas.ew_table.items()
                if key in keyset and val <= et
            ])
            # print "\tET=", et, "\tInter_CxG EW:",num_ew_intercxg, "\tInter_CxG Edge:", num_edge_intercxg, "\tInter_CxG Ix:", num_potential_ix_intercxg
            _text += "\tET= " + str(et) + ":\tInter_CxG EW: " + str(num_ew_intercxg) + "\tInter_CxG Edge: "\
                     + str(num_edge_intercxg) + "\tInter_CxG Ix: " + str(num_potential_ix_intercxg) + "\n"

    return _text
예제 #2
0
def plot_data_gen(filename):
    cxgs = ["cxg_4/", "cxg_3/"]
    for cxg_select in cxgs:
        ewfix = "sameseed/ew/" + cxg_select
        outfix = "sameseed/plot/app3/" + cxg_select

        outfile = infile = filename

        start = time.time()

        mysas = SAS()
        mysas.import_states(ewfix + infile)
        # mysas.import_cs(gcfix + infile)
        # mysas.assign_channels()
        #
        # app1_bw = eval.get_plotdata_bandwidth(mysas)
        # app1_ix_ic = eval.get_plotdata_inter_cxg_ix_per_ch(mysas)
        #
        # eval.save_content(app1_bw, outfix + outfile + "_app1.bw")
        # # keys for .get()
        # # "avg_bw_actual":  one value for Avg. Bandwidth per CBSD
        # # "cdf_bw_actual":  cdf for Avg. BW
        #
        # eval.save_content(app1_ix_ic, outfix + outfile + "_app1.ixic")
        # # keys for .get()
        # # "dbm_per_ch": cdf for Avg. inter-CxG ix
        # # "avg_ix_per_ch_per_cbsd": one value for Avg. inter-CxG ix per CBSD
        # # "max_noises": cdf for Max. inter-CxG ix
        # # "min_noises": cdf for Min. inter-CxG ix

        for et in [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]:

            app3_bw = eval.get_bw_app3(mysas, et)
            app3_ix_ic = eval.get_ix_app3(mysas, et)

            eval.save_content(app3_bw,
                              outfix + outfile + "_app3_" + str(et) + ".bw")
            # keys for .get()
            # "et": et,
            #  "cdf_bw_max": cdf for Max_BW
            #  "avg_bw_max": one value for Avg. Max_BW per CBSD

            eval.save_content(app3_ix_ic,
                              outfix + outfile + "_app3_" + str(et) + ".ixic")
            # keys for .get()
            # "et": et,
            # "cdf_ix":     cdf for inter-CxG ix
            # "avg_ix_max": one value for Avg. inter-CxG ix per CBSD

        stop = time.time()

        print infile, cxg_select, "ready! in", "{0:.4f}".format(
            stop - start), "seconds"
예제 #3
0
def plot_data(filename):
    cxgs = ["cxg_4/"]  #, "cxg_3/"]
    for cxg_select in cxgs:
        ewfix = "simpseed/ew/" + cxg_select
        infile = filename

        start = time.time()

        mysas = SAS()
        mysas.import_states(ewfix + infile)

        cbsds_1 = {cbsd for cbsd in mysas.CBSDs if cbsd.CxG == 1}

        for cbsd in cbsds_1:
            print cbsd.id, ":\t", len(
                [val for val in cbsd.coverage.values() if val >= -96])
        color = ["red", "blue"]
        clr = 0
        for cbsd in mysas.CBSDs:
            if cbsd.id in ["36"]:
                cvg = {
                    key
                    for key in cbsd.coverage.keys()
                    if cbsd.coverage.get(key) >= -96
                }
                coordinate = [mysas.grids.get(key) for key in cvg]
                if len(coordinate) > 0:
                    Ys, Xs = zip(*coordinate)
                    # Coverage[cbsd.id] = {"X": Xs, "Y": Ys, "color": clr}

                    plt.scatter(Xs,
                                Ys,
                                s=20,
                                c=color[clr],
                                alpha=0.3,
                                marker="s",
                                lw=0)
                    clr += 1

                plt.scatter(cbsd.longitude,
                            cbsd.latitude,
                            s=50,
                            c="white",
                            marker="^")

        lats = [x[1] for x in mysas.grids.values()]
        lons = [x[0] for x in mysas.grids.values()]
        plt.xlim(min(lats), max(lats))
        plt.ylim(min(lons), max(lons))
        # plt.savefig("simpseed/plot/" + outfile + ".png")
        plt.show()
        plt.close()
예제 #4
0
def plot_data_gen(filename):
    cxgs = ["cxg_4/", "cxg_3/"]
    for cxg_select in cxgs:
        ewfix = "sameseed/ew/" + cxg_select
        outfix = "sameseed/plot/app3/" + cxg_select
        outfile = infile = filename

        start = time.time()

        mysas = SAS()
        mysas.import_states(ewfix + infile)

        # Total Bandwidth
        Total_BandWidth = len(mysas.channels) * 10.0

        # Total CxG
        cxg_nums = {cbsd.CxG for cbsd in mysas.CBSDs}

        bw_content = {}
        for et in ets:
            # Max Bandwidth Assigned to each CBSD
            assignment = mysas.get_approach_3(et)
            bw_max_per_cbsd = {
                key: Total_BandWidth / val[0]
                for key, val in assignment.items()
            }

            tmp = {
                "CxG_" + str(cxg_num): np.mean([
                    val for key, val in bw_max_per_cbsd.items() if key in
                    {cbsd.id
                     for cbsd in mysas.CBSDs if cbsd.CxG == cxg_num}
                ])
                for cxg_num in cxg_nums
            }

            bw_content[str(et)] = tmp

        # print bw_content
        eval.save_content(bw_content, outfix + outfile + "_app3.cxgbw")
        stop = time.time()

        print infile, cxg_select, "ready! in", "{0:.4f}".format(
            stop - start), "seconds"
예제 #5
0
def gc(inputfile, outputfile):

    input_folder = "experiment/multi/ew/"
    output_folder = "experiment/multi/gc/"

    for set_cxg in [True]:

        # cxg_fix = "cxg_y/" if set_cxg else "cxg_n/"
        cxg_fix = ""

        infile = input_folder + cxg_fix + inputfile
        outfile = output_folder + cxg_fix + outputfile

        mysas = SAS()
        mysas.import_states(infile)

        mysas.graph_coloring_all_until_satisfied()

        mysas.export_states(outfile)
        mysas.export_cs(outfile)
예제 #6
0
def ew(inputfile, outputfile, pm):

    input_folder = "sameseed/scene/"
    output_folder = "sameseed/ew/"

    cxg_fix = "cxg_4/"

    infile = input_folder + inputfile
    outfile = output_folder + cxg_fix + outputfile

    mysas = SAS(coordination="area", propagation=pm)
    mysas.load_CBSDs_file(infile)
    mysas.create_ew_table()
    mysas.export_states(outfile)
예제 #7
0
def assign_cxg(filename):
    cxgs = [3]
    for cxg_select in cxgs:
        ewfix = "sameseed/ew/" + "cxg_4/"
        outfix = "sameseed/ew/cxg_" + str(cxg_select) + "/"

        outfile = infile = filename

        start = time.time()

        mysas = SAS()
        mysas.import_states(ewfix + infile)

        num_of_cbsds = len(mysas.CBSDs)
        np.random.seed(0)
        cxgs = np.random.choice(range(cxg_select), num_of_cbsds)

        for cbsd, cxg in zip(mysas.CBSDs, list(cxgs)):
            cbsd.set_cxg(cxg)

        mysas.export_states(outfix + outfile)

        stop = time.time()

        print infile, "cxg_" + str(cxg_select), "ready! in", "{0:.4f}".format(
            stop - start), "seconds"
예제 #8
0
def diffseed(inputfile, outputfile, pm, myseed):

    np.random.seed(myseed)
    input_folder = "sameseed/ew/"
    output_folder = "sameseed/repeat/ew/"

    cxg_fix = "cxg_4/"

    infile = input_folder + cxg_fix + inputfile
    outfile = output_folder + cxg_fix + outputfile

    param = copy.deepcopy(sc.DefaultParam.Param)

    mysas = SAS(coordination="area", propagation=pm)
    mysas.import_states(infile)

    for cbsd in mysas.CBSDs:  # Reset agl and eirp
        rw = rws[rts.index(cbsd.region_type)]
        cat = cbsd.antenna_cat

        prob_height = param[cat + rw + "_height_ratio"]
        if np.isscalar(prob_height):
            tmp = prob_height
            prob_height = [tmp]

        height_low = param[cat + rw + "_height_low"]
        if np.isscalar(height_low):
            tmp = height_low
            height_low = [tmp]

        height_high = param[cat + rw + "_height_high"]
        if np.isscalar(height_high):
            tmp = height_high
            height_high = [tmp]

        eirp_low = param[cat + rw + "_eirp_low"]
        eirp_high = param[cat + rw + "_eirp_high"]

        i = np.random.choice(range(len(prob_height)), p=prob_height)
        agl = np.random.choice(
            range(int(height_low[i]),
                  int(height_high[i]) + 1))
        eirp = np.random.choice(range(int(eirp_low), int(eirp_high) + 1))

        cbsd.height = agl
        cbsd.set_power(eirp)

    mysas.create_ew_table()
    mysas.export_states(outfile)
예제 #9
0
def ew(inputfile, outputfile):

    input_folder = "experiment/multi/scene/"
    output_folder = "experiment/multi/ew/"

    for set_cxg in [True]:

        # cxg_fix = "cxg_y/" if set_cxg else "cxg_n/"
        cxg_fix = ""
        infile = input_folder + inputfile
        outfile = output_folder + cxg_fix + outputfile

        mysas = SAS(coordination="area")
        mysas.load_CBSDs_file(infile)
        mysas.create_ew_table()

        mysas.export_states(outfile)
예제 #10
0
def plot_data_gen(filename):
    ewfix = gcfix = "experiment/multi/gc/"
    outfix = "experiment/multi/plotdata/"

    outfile = infile = filename

    start = time.time()

    mysas = SAS()
    mysas.import_states(ewfix + infile)
    mysas.import_cs(gcfix + infile)
    mysas.assign_channels()

    data_bw = eval.get_plotdata_bandwidth(mysas)
    data_ix = eval.get_plotdata_interference(mysas)

    eval.save_content(data_bw, outfix + outfile + ".bwcdf")
    eval.save_content(data_ix, outfix + outfile + ".ixcdf")

    stop = time.time()

    print infile, "ready! in", "{0:.4f}".format(stop-start), "seconds"
예제 #11
0
def plot_data_gen(filename):
    cxgs = ["cxg_4/", "cxg_3/"]
    for cxg_select in cxgs:
        ewfix = "sameseed/ew/" + cxg_select
        outfix = "sameseed/plot/app3/" + cxg_select
        outfile = infile = filename

        start = time.time()

        mysas = SAS()
        mysas.import_states(ewfix + infile)

        potential_pairs_list = {et: mysas.get_approach_3(et) for et in ets}

        cxg_nums = {cbsd.CxG for cbsd in mysas.CBSDs}

        coverage = {}
        noises = {}
        for cxg_num in cxg_nums:
            noises_cxg = {}
            # find the coverage of all CBSDs in the CxG
            grids_covered = {
                key
                for cbsd in mysas.CBSDs if cbsd.CxG == cxg_num
                for key, val in cbsd.coverage.items() if val >= min_rx
            }

            coverage["CxG_" + str(cxg_num)] = list(grids_covered)

            # for each grid, find the CBSDs cover and interfere it
            for grid_id in grids_covered:
                noises_grid = {}
                cbsds_in_cxg = {
                    cbsd
                    for cbsd in mysas.CBSDs if cbsd.CxG == cxg_num
                    and cbsd.coverage.get(grid_id) >= min_rx
                }
                cbsds_out_cxg = {
                    cbsd
                    for cbsd in mysas.CBSDs if cbsd.CxG != cxg_num
                    and cbsd.coverage.get(grid_id) >= min_rx
                }

                # under each edge threshold
                for et in ets:
                    noise_et = {}
                    potential_pairs = potential_pairs_list[
                        et]  # {cbsd: (cluster_size, neighbors)}

                    for cbsd_out in cbsds_out_cxg:
                        # mark cbsd_out if has potential edges with any of the CBSD in the CxG
                        if any([
                                cbsd_out.id
                                in potential_pairs.get(cbsd_in.id)[1]
                                for cbsd_in in cbsds_in_cxg
                        ]):
                            noise_et[cbsd_out.id] = cbsd_out.coverage.get(
                                grid_id)

                    if len(noise_et) > 0:
                        noise_et["all"] = eval.get_per_unit_dbm(
                            noise_et.values())  # Aggregated
                        noises_grid[str(et)] = noise_et
                if len(noises_grid) > 0:
                    noises_cxg[str(grid_id)] = noises_grid

            noises["CxG_" +
                   str(cxg_num)] = noises_cxg if len(noises_cxg) > 0 else None

        eval.save_content(
            {
                "noise": noises,
                "coverage": coverage,
                "grid": mysas.grids
            }, outfix + outfile + "_app3.noise")
        stop = time.time()

        print infile, cxg_select, "ready! in", "{0:.4f}".format(
            stop - start), "seconds"
예제 #12
0
def plot_data(filename):
    cxgs = ["cxg_4/"]
    for cxg_select in cxgs:
        infix = "experiment/plot/sameseed/" + cxg_select
        infile = filename + "_app3.noise"

        start = time.time()

        content = eval.load_content(infix + infile)

        mysas = SAS()
        mysas.import_states(infix + filename)

        cxgs = content.get("coverage").keys()
        coverage = content.get("coverage")
        noises = content.get("noise")
        grids = content.get("grid")

        cov = {x for val in coverage.values() for x in val}
        # print "Coverage all CBSDS:", len(cov)

        #
        # ix_value_by_et = {}
        # ix_coverage_by_et = {}

        # signal_coverage = {target_cxg : len(coverage.get(target_cxg)) for target_cxg in cxgs}

        for et in ets:

            # print "ET=", et, ":"

            ix_value_by_cxg = {}
            ix_coverage_by_cxg = {}
            # for target_cxg in cxgs:
            target_cxg_coverage = len(coverage.get(target_cxg))

            # target_cxg_noises_map = {key: val.get(str(et)).get("all")
            #                          for key, val in noises.get(target_cxg).items()
            #                          if noises.get(target_cxg).get(key).get(str(et)) is not None}

            in_cbsds_id = {cbsd.id for cbsd in mysas.CBSDs if cbsd.CxG == 0}
            effew = {
                key: val
                for key, val in mysas.ew_table.items()
                if len(in_cbsds_id.intersection(key)) == 1 and et -
                0.1 < val <= et
            }

            target_pairs = {
                key: len(val.get(str(et))) - 1
                for key, val in noises.get(target_cxg).items()
                if noises.get(target_cxg).get(key).get(str(et)) is not None
            }

            # print "\tGrids: ", len(target_pairs.keys())
            # print "\tCBSD-Grid Ix: ", sum(target_pairs.values())
            # print "\tCBSDs/Grid", sum(target_pairs.values())*1.0/len(target_pairs.keys())
            print "\t", len(effew)

            #
            # interfered_grids = len(target_cxg_noises_map) if target_cxg_noises_map is not None else 0
            # avg_noise_level = eval.get_per_unit_dbm(target_cxg_noises_map.values(), interfered_grids * 1.0)
            #
            #     ix_coverage_by_cxg[target_cxg] = interfered_grids * 100.0 / target_cxg_coverage
            #     ix_value_by_cxg[target_cxg] = avg_noise_level
            #
            # ix_coverage_by_et[str(et)] = ix_coverage_by_cxg
            # ix_value_by_et[str(et)] = ix_value_by_cxg

        # eval.save_content(
        #     {"signal_coverage": signal_coverage, "ix_coverage": ix_coverage_by_et, "noise": ix_value_by_et},
        #     outfix + filename + ".ixcovval")
        stop = time.time()

        print infile, cxg_select, "ready! in", "{0:.4f}".format(
            stop - start), "seconds"
예제 #13
0
def plot_data_gen(filename):
    cxgs = ["cxg_4/"]
    for cxg_select in cxgs:
        ewfix = "sameseed/repeat/ew/" + cxg_select
        outfix = "sameseed/repeat/plot/app3/" + cxg_select
        outfile = infile = filename

        mysas = SAS()
        mysas.import_states(ewfix + infile)

        # Total Bandwidth
        Total_BandWidth = len(mysas.channels) * 10.0

        # Total CxG
        cxg_nums = {cbsd.CxG for cbsd in mysas.CBSDs}

        bw_content = {}
        for et in ets:
            # Max Bandwidth Assigned to each CBSD
            assignment = mysas.get_approach_3(et)
            bw_max_per_cbsd = {key: Total_BandWidth / val[0] for key, val in assignment.items()}

            tmp = {"CxG_" + str(cxg_num): np.mean([val for key, val in bw_max_per_cbsd.items()
                                                   if key in {cbsd.id for cbsd in mysas.CBSDs if cbsd.CxG == cxg_num}])
                   for cxg_num in cxg_nums}

            bw_content[str(et)] = tmp

        # print bw_content
        eval.save_content(bw_content, outfix + outfile + "_app3.cxgbw")
        print "bandwidth ready"


        potential_pairs_list = {et: mysas.get_approach_3(et) for et in ets}

        cxg_nums = {cbsd.CxG for cbsd in mysas.CBSDs}

        coverage = {}
        noises = {}
        for cxg_num in cxg_nums:
            noises_cxg = {}
            # find the coverage of all CBSDs in the CxG
            grids_covered = {key for cbsd in mysas.CBSDs if cbsd.CxG == cxg_num
                             for key, val in cbsd.coverage.items() if val >= min_rx}

            coverage["CxG_"+str(cxg_num)] = list(grids_covered)

            # for each grid, find the CBSDs cover and interfere it
            for grid_id in grids_covered:
                noises_grid = {}
                cbsds_in_cxg = {cbsd for cbsd in mysas.CBSDs if cbsd.CxG == cxg_num and cbsd.coverage.get(grid_id) >= min_rx}
                cbsds_out_cxg = {cbsd for cbsd in mysas.CBSDs if cbsd.CxG != cxg_num and cbsd.coverage.get(grid_id) >= min_rx}

                # under each edge threshold
                for et in ets:
                    noise_et = {}
                    potential_pairs = potential_pairs_list[et]      # {cbsd: (cluster_size, neighbors)}

                    for cbsd_out in cbsds_out_cxg:
                        # mark cbsd_out if has potential edges with any of the CBSD in the CxG
                        if any([cbsd_out.id in potential_pairs.get(cbsd_in.id)[1] for cbsd_in in cbsds_in_cxg]):
                            noise_et[cbsd_out.id] = cbsd_out.coverage.get(grid_id)

                    if len(noise_et) > 0:
                        noise_et["all"] = eval.get_per_unit_dbm(noise_et.values())      # Aggregated
                        noises_grid[str(et)] = noise_et
                if len(noises_grid) > 0:
                    noises_cxg[str(grid_id)] = noises_grid

            noises["CxG_"+str(cxg_num)] = noises_cxg if len(noises_cxg) > 0 else None

        eval.save_content({"noise": noises, "coverage": coverage, "grid": mysas.grids}, outfix + outfile + "_app3.noise")
        print "noise ready"