bap/final.py
def initial_feasible_configuration():
    """Generates one feasible allocation, along with its coverage.

    Returns:
      A feasible allocation and its coverage.
    """
    if verbose:
        print('Generating the initial column')
        
    m = gp.Model()
    x = m.addVars(len(bases), lb=0, ub=max_practical_ambulances, vtype=gp.GRB.INTEGER, name='x')

    # Constraint: Don't use more than the available number of ambulances.
    m.addConstr(gp.quicksum(x) <= num_ambulances)

    # Constraint: The configuration must sufficiently cover a portion of the zones.
    c = m.addVars(n, vtype=gp.GRB.BINARY)
    for i in range(n):
        m.addGenConstrIndicator(c[i], True, gp.quicksum(x[j]*adj[bases[j], i] for j in range(len(bases))) >= sufficient[i])
        m.addGenConstrIndicator(c[i], False, gp.quicksum(x[j]*adj[bases[j], i] for j in range(len(bases))) <= sufficient[i] - 1)
    m.addConstr(gp.quicksum(c) >= math.ceil(min_coverage*n))
    
    m.update()
    m.optimize()
    allocation = [round(m.getVarByName(f'x[{i}]').X) for i in range(len(x))]
    coverage = utrecht.allocation_coverage(allocation)
    
    return allocation, coverage
Generates one feasible allocation, along with its coverage.

    Returns:
      A feasible allocation and its coverage.
    
Generates one feasible allocation, along with its coverage.
Generates one feasible allocation along with its coverage .
def initial_feasible_configuration():
    if verbose:
        print('Generating the initial column')
    m = gp.Model()
    x = m.addVars(len(bases), lb=0, ub=max_practical_ambulances, vtype=gp.GRB.INTEGER, name='x')
    m.addConstr(gp.quicksum(x) <= num_ambulances)
    c = m.addVars(n, vtype=gp.GRB.BINARY)
    for i in range(n):
        m.addGenConstrIndicator(c[i], True, gp.quicksum(x[j]*adj[bases[j], i] for j in range(len(bases))) >= sufficient[i])
        m.addGenConstrIndicator(c[i], False, gp.quicksum(x[j]*adj[bases[j], i] for j in range(len(bases))) <= sufficient[i] - 1)
    m.addConstr(gp.quicksum(c) >= math.ceil(min_coverage*n))
    m.update()
    m.optimize()
    allocation = [round(m.getVarByName(f'x[{i}]').X) for i in range(len(x))]
    coverage = utrecht.allocation_coverage(allocation)
    return allocation, coverage
def initial_feasible_configuration ( ) : if verbose : print ( 'Generating the initial column' ) m = gp . Model ( ) x = m . addVars ( len ( bases ) , lb = 0 , ub = max_practical_ambulances , vtype = gp . GRB . INTEGER , name = 'x' ) m . addConstr ( gp . quicksum ( x ) <= num_ambulances ) c = m . addVars ( n , vtype = gp . GRB . BINARY ) for i in range ( n ) : m . addGenConstrIndicator ( c [ i ] , True , gp . quicksum ( x [ j ] * adj [ bases [ j ] , i ] for j in range ( len ( bases ) ) ) >= sufficient [ i ] ) m . addGenConstrIndicator ( c [ i ] , False , gp . quicksum ( x [ j ] * adj [ bases [ j ] , i ] for j in range ( len ( bases ) ) ) <= sufficient [ i ] - 1 ) m . addConstr ( gp . quicksum ( c ) >= math . ceil ( min_coverage * n ) ) m . update ( ) m . optimize ( ) allocation = [ round ( m . getVarByName ( f'x[{i}]' ) . X ) for i in range ( len ( x ) ) ] coverage = utrecht . allocation_coverage ( allocation ) return allocation , coverage
Generates one feasible allocation, along with its coverage.
Generates one feasible allocation along with its coverage .
"""Generates one feasible allocation, along with its coverage.

    Returns:
      A feasible allocation and its coverage.
    """ # Constraint: Don't use more than the available number of ambulances. # Constraint: The configuration must sufficiently cover a portion of the zones.
A feasible allocation and its coverage.
A feasible allocation and its coverage .