def amc_reward_fn(env, top1, top5, vloss, total_macs):
    """This reward punishes the agent when it produces networks that don't comply with the MACs resource-constraint,
    (the negative reward is in proportion to the network density).  Otherwise, the reward is the Top1 accuracy.
    """
    if not env.is_macs_constraint_achieved(total_macs):
        current_density = total_macs / env.dense_model_macs
        reward = env.amc_cfg.target_density - current_density
    else:
        reward = top1 / 100
    return reward