""" Test colorings for edgeless graphs. Copyright 2020. Siwei Wang. """ from pytest import mark from common import create_edgeless, parameters, len_iter, check_surjective @mark.parametrize('vertices,colors', parameters(7, 8)) def test_edgeless(vertices: int, colors: int): """Test edgeless graph colorings.""" graph = create_edgeless(vertices) colorings = graph.colorings(colors) num_colorings = len_iter(colorings) assert num_colorings == colors**vertices assert check_surjective(graph, colors, num_colorings)
def __init__( self,n=3000 ): self.params = parameters() self.n = n
## IMPORT MODULES import sys # basic import traceback sys.path.append('.') import common, objects, loaders if __name__ == '__main__': try: common.progress('loading tool parameters') # common.message(common.parameters(14)) interLayer, query, interFromIDFld, interToIDFld, interStrengthFld = common.parameters(5) inSlots = {'from' : interFromIDFld, 'to' : interToIDFld, 'value' : interStrengthFld} outSlots = {'in' : 'SIG_IN', 'out' : 'SIG_OUT'} common.progress('loading interactions') inter = loaders.InteractionReader(interLayer, slots, where=query).read() common.progress('selecting significant interactions') signif = objects.Interactions.selectSignificant(inter) common.progress('writing output') loaders.InteractionPresenceMarker(interLayer, inSlots, outSlots, where=query).mark(signif) common.done() except: common.message(traceback.format_exc()) raise
""" Test colorings for cycle graphs. Copyright 2020. Siwei Wang. """ from pytest import mark from common import parameters, create_cycle, len_iter, check_surjective def expected(vertices: int, colors: int) -> int: """Compute expected colorings with chromatic polynomial.""" return (colors - 1)**vertices + (-1)**vertices * (colors - 1) @mark.parametrize('vertices,colors', parameters(7, 9, non_zero=True)) def test_cycle(vertices: int, colors: int): """Test path cycle colorings.""" graph = create_cycle(vertices) colorings = graph.colorings(colors) num_colorings = len_iter(colorings) assert num_colorings == expected(vertices, colors) assert check_surjective(graph, colors, num_colorings)
## IMPORT MODULES import sys sys.path.append('.') import common # useful shortcut functions for arcpy and datamodel import delimit_functional_regions common.debugMode = True common.progress('loading tool parameters') # whoa, have fun with the parameters zoneLayer, \ zoneIDFld, zoneMassFld, zoneCoopFld, zoneRegFld, zoneColFld, coreQuery, \ outRegFld, doOutCoreStr, outColFld, measureFlds, \ interTable, interFromIDFld, interToIDFld, interStrFld, \ neighTable, exclaveReassignStr, oscillationStr, doSubBindStr, doCoreFirstStr, \ aggregSorterStr, threshold1Str, threshold2Str = common.parameters(23) delimit_functional_regions.main(zoneLayer, zoneIDFld, zoneMassFld, zoneCoopFld, zoneRegFld, zoneColFld, coreQuery, outRegFld, doOutCoreStr, outColFld, measureFlds, interTable, interFromIDFld, interToIDFld, interStrFld, neighTable, exclavePenalStr=('100' if common.toBool(exclaveReassignStr, 'exclave reassignment switch') else '0'), aggregSorterStr=aggregSorterStr, verifier1Str='MASS', threshold1Str=threshold1Str, verifier2Str='HINTERLAND_MASS', threshold2Str=threshold2Str, oscillationStr=oscillationStr, doSubBindStr=doSubBindStr, doCoreFirstStr=doCoreFirstStr)
#!/usr/bin/python import numpy as np import data_tools import ml_tools import pickle as pk from common import parameters if __name__ == "__main__": params = parameters() peptides = data_tools.read_data( params.data_path ) for n in params.ntrain : print n benchmark = ml_tools.rt_benchmark( peptides, 'elude', 'gp', n , params.nparts, params.train_ratio ) models = ml_tools.single_train_gp( benchmark ) save_path = params.save_tmp % ( params.data_root, params.models_tag, n ) with open( save_path, 'w' ) as ff : pk.dump( [ models ], ff ) ff.close() models = None
arcpy.env.overwriteOutput = 1 # Creates a neighbourhood table of provided zones according to the principle of network neighbourhood - two zones are neighbours if they are connected by a route along the network that does not pass through a third settlement and that is most reasonable according to the provided impedance # Settlement areas must not cross zone boundaries! TMP_ZONE_NEGBUF = "tmp_zonecore" TMP_SETTL_NEGBUF = "tmp_settlcore" TMP_ROUTES = "tmp_routes" TMP_ROUTE_ER = "tmp_rerase" TMP_ROUTE_SINGLE = "tmp_rsing" TMP_RSING_LAY = "tmp_rsing_lay" common.progress("parsing attributes") zoneAreas, zonePts, zoneIDFld, settlAreas, network, impedance, cutoff, cutoffFld, numToFind, location, outputName = common.parameters( 11 ) common.progress("initializing route creator") # create network connections - see comments for create_network_connections conn = BulkConnectionCreator(zonePts, network, impedance, cutoff, numToFind, location) common.progress("loading data") conn.load() common.progress("solving routes") conn.solve() common.progress("joining attributes") conn.joinFields([zoneIDFld]) common.progress("creating routes") conn.output(TMP_ROUTES) # routes between the zone central points conn.close() arcpy.env.workspace = location # prepare the settlement areas - remove all lying close to the border