Fix service area case

This commit is contained in:
wqy
2023-06-27 20:51:09 +08:00
parent 9d90643b3b
commit 4c6e257d1d
5 changed files with 31 additions and 15 deletions

11
dev.py Normal file
View File

@@ -0,0 +1,11 @@
from tjnetwork import *
p = 'dev'
read_inp(p, './inp/net3.inp', '3')
open_project(p)
sass = calculate_service_area(p)
assert len(sass) == 25
print(sass[0])
print(sass[1])

View File

@@ -1,11 +0,0 @@
from tjnetwork import *
if __name__ == '__main__':
p = 'net4'
copy_project('net3', p)
open_project(p)
set_vertex(p, ChangeSet({'link' : '20', 'coords': [{'x': 20.0, 'y': 40.0}, {'x': 40.0, 'y': 20.0}]}))
set_restore_operation_to_current(p)
close_project(p)
for i in range(1, 11):
copy_project(p, f'{p}_{i}')

View File

@@ -33,7 +33,7 @@ class Output:
def _check(self, result):
if result != 0:
if result != 0 and result != 10:
msg = ctypes.c_char_p()
code = self._lib.ENR_checkError(self._handle, ctypes.byref(msg))
assert code == result

View File

@@ -2,6 +2,9 @@ ERROR_CODE = {}
# EPANET 2 Error Messages
ERROR_CODE['0'] = "ok"
ERROR_CODE['10'] = "Warning: model run issued warnings"
ERROR_CODE['101'] = "insufficient memory available"
ERROR_CODE['102'] = "no network data available"
ERROR_CODE['103'] = "hydraulic solver not opened"
@@ -75,3 +78,15 @@ ERROR_CODE['306'] = "hydraulics file does not match network data"
ERROR_CODE['307'] = "cannot read hydraulics file"
ERROR_CODE['308'] = "cannot save results to file"
ERROR_CODE['309'] = "cannot save results to report file"
ERROR_CODE['411'] = "Input Error 411: no memory allocated for results"
ERROR_CODE['412'] = "Input Error 412: binary file hasn't been opened"
ERROR_CODE['421'] = "Input Error 421: invalid parameter code"
ERROR_CODE['422'] = "Input Error 422: reporting period index out of range"
ERROR_CODE['423'] = "Input Error 423: element index out of range"
ERROR_CODE['434'] = "File Error 434: unable to open binary file"
ERROR_CODE['435'] = "File Error 435: invalid binary file type"
ERROR_CODE['436'] = "File Error 436: no results in binary file"
ERROR_CODE['ERR'] = "Error: An unknown error has occurred"

View File

@@ -6192,8 +6192,9 @@ class TestApi:
sass = calculate_service_area(p)
assert len(sass) == 25
assert sass[0] == {'River': ['River', '60', '61', '123', '601', '121', '120', '119', '125', '117', '257', '151', '157', '127', '153', '115', '261', '259', '149', '159', '20', '129', '111', '113', '107', '263', '147', '161', '3', '131', '139', '109', '197', '193', '105', '145', '163', '195', '141', '103', '191', '101', '164', '265', '143', '187', '166', '169', '267', '15', '204', '167', '171', '269', '189', '185', '173', '271', '183', '184', '199', '181', '179', '205', '201', '273', '35', '177', '40', '207', '203', '275', '1', '206', '208', '209', '211', '213', '237', '215', '229', '217', '231', '219', '225'], '2': ['2', '50', '255', '247', '253', '251', '241', '249', '239', '243', '237', '229', '231']}
assert sass[1] == {'River': ['River', '60', '61', '123', '601', '121', '120', '119', '125', '117', '151', '157', '127', '153', '115', '149', '159', '20', '129', '111', '113', '147', '161', '3', '131', '139', '197', '193', '145', '163', '195', '141', '191', '267', '164', '265', '143', '187', '189', '166', '169', '15', '204', '183', '167', '171', '269', '185', '179', '173', '271', '184', '40', '199', '181', '205', '1', '201', '273', '35', '177', '207', '203', '275', '206', '208', '209', '211', '213', '237', '215', '229', '239', '217', '231', '241', '249', '219', '225', '243', '247'], 'Lake': ['Lake', '10', '101', '103', '105', '109', '107', '263', '111', '115', '259', '261', '113', '197', '257', '117', '193', '191', '120', '267', '187', '119', '189', '265', '204', '151', '157', '183', '169', '185', '149', '159', '179', '167', '171', '269', '184', '147', '161', '40', '173', '271', '205', '145', '163', '195', '1', '199', '181', '207', '141', '164', '201', '273', '35', '177', '206', '143', '166', '203', '275', '208', '15', '209', '211', '213', '237', '215', '229', '239', '217', '231', '241', '249', '219', '225', '243', '247'], '2': ['2', '50', '255', '247', '253', '251', '249']}
assert sass[0] == {'River': ['River', '60', '61', '123', '601', '121', '120', '119', '117', '257', '151', '157', '115', '259', '261', '149', '159', '111', '113', '263', '147', '161', '197', '193', '105', '145', '163', '195', '191', '267', '107', '141', '164', '265', '187', '189', '143', '166', '169', '204', '15', '167', '171', '269', '185', '173', '271', '184', '199', '205', '201', '207', '273', '203', '275'], '1': ['1', '40', '179', '177', '183', '181', '185', '189', '35', '271', '184', '187', '171', '205', '204', '173', '207', '273', '199', '275', '201', '203'], '2': ['2', '50', '255', '247', '253', '251', '241', '249', '239', '243', '237', '211', '229', '209', '213', '231', '208', '215', '206', '217', '207', '219', '225', '275', '201', '203'], '3': ['3', '20', '127', '125', '129', '121', '153', '131', '139', '120', '119', '151', '141', '117', '257', '157', '149', '143', '115', '259', '261', '159', '147', '15', '111', '113', '263', '161', '145', '197', '193', '105', '163', '195', '191', '267', '107', '164', '265', '187', '189', '166', '169', '204', '167', '171', '269', '185', '173', '271', '184', '199', '205', '201', '207', '273', '203', '275']}
assert sass[1] == {'River': ['River', '60', '61', '123', '601', '121', '120', '119', '117', '257', '151', '157', '115', '259', '261', '149', '159', '111', '113', '263', '147', '161', '197', '193', '105', '145', '163', '195', '191', '107', '141', '164', '265', '187', '143', '166', '169', '267', '204', '15', '167', '171', '269', '189', '185', '173', '271', '184', '199', '205', '201', '207', '273', '203', '275'], 'Lake': ['Lake', '10', '101', '103', '105', '109', '107', '111', '115', '113', '197', '193', '191', '187', '204', '185', '184', '205', '207', '273', '275', '199', '201', '203'], '1': ['1', '40', '179', '177', '183', '181', '185', '189', '35', '271', '184', '187', '171', '205', '204', '173', '207', '273', '199', '275', '201', '203'], '2': ['2', '50', '255', '247', '253', '251', '241', '249', '239', '243', '237', '211', '229', '209', '213', '231', '208', '215', '206', '217', '207', '219', '225', '275', '201', '203'], '3': ['3', '20', '127', '125', '129', '121', '153', '131', '139', '120', '119', '151', '141', '117', '257', '157', '149', '143', '115', '259', '261', '159', '147', '15', '111', '113', '263', '161', '145', '197', '193', '105', '163', '195', '191', '107', '164', '265', '187', '166', '169', '267', '204', '167', '171', '269', '189', '185', '173', '271', '184', '199', '205', '201', '207', '273', '203', '275']}
self.leave(p)