def count_var_match(var_names, relation):
    """
    Count the number of common variables between agt_vars and the dimensions
    or relation.

    :param var_names: a list of variable names
    :param relation: a relation object
    :return: the number of common variable
    """
    match = 0
    for v in relation.dimensions:
        if v.name in var_names:
            match += 1
    return match