views:

41

answers:

2

I am creating an Ad system for an ASP.NET website. The website has a section for advertisers. They register their and posts there ads, They will pay the maximum budget for the ad first, There is a daily budget , so the advertiser can control his budget, There will be a lot of ads from different advertisers to show in the website. The ads has two attributes maximum budget and daily budget, How can i select ads , How many times an ad can display, Can anyone give me a method or algorithm for that.

A: 

I would recommend looking at scheduling algorithms.

For example, you could use the budget to determine a number of times / period (day/week/etc), and use that as a weighting factor in a weighted round robin schedule. This would be a simple way to balance out requests from different advertisers evenly through time. (NOTE: The link above is more geared towards network packet scheduling, but the basic algorithm would work...)

Reed Copsey
+1  A: 

Hey Priyan, here's how we handle it in AdServerBeans (http://www.adserverbeans.com - it's open source, you can check the source code):

DROP FUNCTION if exists get_speed;
CREATE FUNCTION get_speed(from_date DATETIME, to_date DATETIME, views_limit INT, views_served INT, now_date_time TIMESTAMP)
  RETURNS double
  DETERMINISTIC
  NO SQL
BEGIN
  DECLARE banner_total_serving_time INTEGER;
  DECLARE banner_served_time       INTEGER;
  DECLARE percent_time_served        DOUBLE;
  DECLARE percent_ad_events_served    DOUBLE;
  IF (views_limit IS NULL OR views_limit=0) THEN RETURN -1;END IF;

  IF (views_served IS NULL) THEN SET views_served = 0;END IF;
  IF (banner_total_serving_time = 0) THEN SET banner_total_serving_time = 1;END IF;
  IF (views_limit = 0) THEN SET views_limit = 1;END IF;

  SET banner_total_serving_time = TIMESTAMPDIFF(SECOND, from_date, to_date);
  SET banner_served_time = TIMESTAMPDIFF(SECOND, from_date, now_date_time);
  SET percent_time_served = (100 * banner_served_time) / banner_total_serving_time;
  SET percent_ad_events_served = (100 * views_served) / views_limit;
  RETURN percent_ad_events_served - percent_time_served;
END
;;

This MySQL function returns negative or positive number. Negative if we are underperforming, positive if overperforming. Underperforming - serve, overperforming - skip to the next banner or not serve.

Input parameters are self-explanatory I hope.

Vitaly Sazanovich