コード例 #1
0
ファイル: test_ipf.py プロジェクト: caleffiufsm/aequilibrae
    def test_fit(self):
        # The IPF per se
        args = {
            "matrix": matrix,
            "rows": row_vector,
            "row_field": "rows",
            "columns": column_vector,
            "column_field": "columns",
            "nan_as_zero": False,
        }

        fratar = Ipf(**args)
        fratar.fit()

        result = fratar.output
        if (np.nansum(result.matrix_view) -
                np.nansum(row_vector.data["rows"])) > 0.001:
            print(fratar.gap)
            for f in fratar.report:
                print(f)
            self.fail("Ipf did not converge")

        if fratar.gap > fratar.parameters["convergence level"]:
            print(fratar.gap)
            for f in fratar.report:
                print(f)
            self.fail("Ipf did not converge")
コード例 #2
0
    def test_fit(self):
        # The IPF per se
        args = {
            'matrix': matrix,
            'rows': row_vector,
            'row_field': 'rows',
            'columns': column_vector,
            'column_field': 'columns',
            'nan_as_zero': False
        }

        fratar = Ipf(**args)
        fratar.fit()

        result = fratar.output
        if (np.nansum(result.matrix_view) -
                np.nansum(row_vector.data['rows'])) > 0.001:
            print fratar.gap
            for f in fratar.report:
                print f
            self.fail('Ipf did not converge')

        if fratar.gap > fratar.parameters['convergence level']:
            print fratar.gap
            for f in fratar.report:
                print f
            self.fail('Ipf did not converge')
コード例 #3
0
ファイル: ipf_procedure.py プロジェクト: lqwer321/AequilibraE
class IpfProcedure(WorkerThread):
    def __init__(self, parentThread, seed, rows, columns):
        WorkerThread.__init__(self, parentThread)
        self.ipf = Ipf(seed, rows, columns)
        self.error = None

    def doWork(self):
        self.ipf.fit()
        self.emit(SIGNAL("finished_threaded_procedure( PyQt_PyObject )"),0)
コード例 #4
0
ファイル: ipf_procedure.py プロジェクト: wsxbjx/AequilibraE
class IpfProcedure(WorkerThread):
    def __init__(self, parentThread, **kwargs):
        WorkerThread.__init__(self, parentThread)
        self.ipf = Ipf(**kwargs)
        self.report = None

    def doWork(self):
        self.ipf.fit()
        self.report = self.ipf.report
        self.emit(SIGNAL("finished_threaded_procedure( PyQt_PyObject )"),0)
        self.emit(SIGNAL("finished_threaded_procedure( PyQt_PyObject )"),0)
コード例 #5
0
class IpfProcedure(WorkerThread):
    def __init__(self, parentThread, **kwargs):
        WorkerThread.__init__(self, parentThread)
        self.ipf = Ipf(**kwargs)
        self.error = None
        self.report = []

    def doWork(self):
        try:
            self.ipf.fit()
            self.report = self.ipf.report
        except ValueError as e:
            self.error = e
        self.finished_threaded_procedure.emit(0)
コード例 #6
0
ファイル: test_ipf.py プロジェクト: AequilibraE/AequilibraE
    def test_fit(self):
        # The IPF per se
        args = {'matrix': matrix,
                'rows': row_vector,
                'row_field': 'rows',
                'columns': column_vector,
                'column_field': 'columns',
                'nan_as_zero': False}

        fratar = Ipf(**args)
        fratar.fit()

        result = fratar.output
        if (np.nansum(result.matrix_view) - np.nansum(row_vector.data['rows'])) > 0.001:
            print (fratar.gap)
            for f in fratar.report:
                print (f)
            self.fail('Ipf did not converge')

        if fratar.gap > fratar.parameters['convergence level']:
            print (fratar.gap)
            for f in fratar.report:
                print (f)
            self.fail('Ipf did not converge')
コード例 #7
0
 def __init__(self, parentThread, **kwargs):
     WorkerThread.__init__(self, parentThread)
     self.ipf = Ipf(**kwargs)
     self.error = None
     self.report = []
コード例 #8
0
ファイル: ipf_procedure.py プロジェクト: lqwer321/AequilibraE
 def __init__(self, parentThread, seed, rows, columns):
     WorkerThread.__init__(self, parentThread)
     self.ipf = Ipf(seed, rows, columns)
     self.error = None
コード例 #9
0
# %% md

### We now run IPF for the future vectors

# %%
args = {
    "matrix": demand,
    "rows": vectors,
    "columns": vectors,
    "column_field": "destinations",
    "row_field": "origins",
    "nan_as_zero": True,
}

ipf = Ipf(**args)
ipf.fit()

ipf.save_to_project(name="demand_ipfd", file_name="demand_ipfd.aem")
ipf.save_to_project(name="demand_ipfd_omx", file_name="demand_ipfd.omx")

# %%

proj_matrices.list()

# %% md

## Future traffic assignment

# %%
コード例 #10
0
ファイル: test_ipf.py プロジェクト: logicTest2021/aequilibrae
    def test_fit(self):
        proj = Project()
        proj.open(self.proj_dir)
        mats = proj.matrices
        mats.update_database()
        seed = mats.get_matrix('SiouxFalls_omx')
        seed.computational_view('matrix')
        # row vector
        args = {
            "entries": seed.zones,
            "field_names": ["rows"],
            "data_types": [np.float64],
            "memory_mode": True
        }
        row_vector = AequilibraeData()
        row_vector.create_empty(**args)
        row_vector.rows[:] = np.random.rand(seed.zones)[:] * 1000
        row_vector.index[:] = seed.index[:]
        # column vector
        args["field_names"] = ["columns"]
        column_vector = AequilibraeData()
        column_vector.create_empty(**args)
        column_vector.columns[:] = np.random.rand(seed.zones)[:] * 1000
        column_vector.index[:] = seed.index[:]
        # balance vectors
        column_vector.columns[:] = column_vector.columns[:] * (
            row_vector.rows.sum() / column_vector.columns.sum())

        # The IPF per se
        args = {
            "matrix": seed,
            "rows": row_vector,
            "row_field": "rows",
            "columns": column_vector,
            "column_field": "columns",
            "nan_as_zero": False,
        }

        with self.assertRaises(TypeError):
            fratar = Ipf(data='test', test='data')
            fratar.fit()

        with self.assertRaises(ValueError):
            fratar = Ipf(**args)
            fratar.parameters = ['test']
            fratar.fit()

        fratar = Ipf(**args)
        fratar.fit()

        result = fratar.output

        self.assertAlmostEqual(np.nansum(result.matrix_view),
                               np.nansum(row_vector.data["rows"]), 4,
                               "Ipf did not converge")
        self.assertGreater(fratar.parameters["convergence level"], fratar.gap,
                           "Ipf did not converge")

        mr = fratar.save_to_project('my_matrix_ipf', 'my_matrix_ipf.aem')

        self.assertTrue(
            os.path.isfile(os.path.join(mats.fldr, 'my_matrix_ipf.aem')),
            'Did not save file to the appropriate place')

        self.assertEqual(mr.procedure_id, fratar.procedure_id,
                         'procedure ID saved wrong')
        proj.close()