Exemple #1
0
 public static Pset CreateN(int n, int T, double ep, int L, int U) {
   Pset N = new Pset();
   int i;
   for (i = 0; i < n; i++) {
     Parti p = new Parti(T, ep, L, U);
     p.id = i + 1;
     N.addP(p);
   }
   return N;
 }
Exemple #2
0
  // 开始函数,构造出一个process
  public void start() {
    int i;
    for (i = 0; i < n; i++) {
      Parti p = new Parti(T, ep, L, U);
      p.id = i + 1;
      this.N.addP(p);
    }

    // 预算为10000,时间为2000,效率为1到2,总人数为200,stage为10,cost与budget的比例为小于0.01,初始临界值为0.9
    // Process pro = new Process(10000, 2000, 2, 1, 200, 10, 0.01 , 0.9);
  }
Exemple #3
0
 public void setN(Pset N) {
   for (int i = 0; i < N.list.size(); i++) {
     Parti p = N.list.get(i);
     Parti q = new Parti();
     q.id = p.id;
     q.arrival_time = p.arrival_time;
     q.departure_time = p.departure_time;
     q.cost = p.cost;
     q.value = p.value;
     q.pay = 0;
     q.select = false;
     this.N.addP(q);
   }
 }
Exemple #4
0
  public static void main(String[] args) throws Exception {
    // TODO 自动生成的方法存根

    PrintWriter out = new PrintWriter("opt&randomValueWithBudget.txt");
    Process pro = new Process(50, 2, 1, 300, 4, 0.0015, 0.1, 0.9); // T = 50, beta = 0.9
    //		pro.start();
    Pset N = CreateN(pro.n, pro.T, pro.ep, pro.L, pro.U);
    double x = 0.001;
    for (int j = 1; j < 50; j++) {
      //			System.out.println("------------------");
      //			Process pro = new Process(10000+j*500, 50, 2, 1, 300, 4, 0.0015, 0.1, 0.9); 	//T = 50,
      // beta = 0.9
      pro.N = new Pset();
      pro.Sample = new SampleS();
      pro.A = new ArrivedP();
      pro.S = new SelectP();
      pro.l = pro.ll;
      pro.rho = 0.9;
      pro.setB(1500 + j * 100);
      pro.setN(N);
      double optValue = handleOpt(pro);
      double randomValue = handleRandom(pro);
      // optValue *= disc(pro.beta, pro.T/2);
      //			System.out.println(pro.N);
      //			for(int l = 0; l < 5; l++){
      //				pro.N.list.get(l).show();
      //			}
      //			System.out.println(pro.B);
      //			System.out.println(pro.B+"  "+pro.ep+"  "+pro.rho+"  "+pro.n+"  "+pro.beta+" "+pro.T+"
      // "+pro.U+" "+pro.L+" "+"  "+pro.l+"  "+pro.ll+" "+pro.ep);

      double lam1 = pro.calcuLam1();
      double lam2 = pro.calcuLam2();

      //
      pro.lam = lam1 + 1 * x * lam2;
      //			System.out.println("lam1 = "+lam1);
      //			System.out.println("lam2 = "+lam2);
      //			System.out.println("lam = "+pro.lam);
      int t;
      //			for (t = 1; t < pro.T; t++)
      //				System.out.println("T = " + pro.T + " " + "t = " + t + " " + "disc = " + disc(pro.beta,
      // t));

      // pro.showInfo();

      double budget = Math.pow(2, -pro.ll) * pro.B;
      //			System.out.println("budget = "+budget);
      // int t;
      int l = pro.l;
      double value = 0;
      for (t = 1; t <= pro.T; t++) {
        //				System.out.println("-----------------时刻" + t + "----------------------");
        //				System.out.println("这个阶段的预算为:" + budget + "," + "临界值为: " + pro.rho);
        for (Parti p : pro.N.list) {
          if (p.arrival_time == t) {
            //						p.show();
            pro.A.addP(p);
            //						System.out.println("在时刻" + t + "添加了一个用户" + p.id);
          }
        }
        Collections.sort(pro.A.list);
        for (int i = 0; i < pro.A.list.size(); i++) {
          Parti p = pro.A.list.get(i);
          //					System.out.println("*******对用户:" + p.id + "进行判断********");
          //					p.show();
          // System.out.println(t);
          //					System.out.println(p.value * disc(pro.beta, t) / p.cost + "##" + pro.rho);
          //					System.out.println(p.value * disc(pro.beta, t) / pro.rho + pro.S.totalPay() + "##"
          // + budget);

          if (p.value * disc(pro.beta, t) / p.cost >= pro.rho
              && p.value * disc(pro.beta, t) / pro.rho + pro.S.totalPay() <= budget) {
            //						p.show();
            //						System.out.println("又选择了一个!");
            p.pay = p.value * disc(pro.beta, t) / pro.rho;
            pro.Sample.addP(p);
            pro.S.addP(p);
            p.select = true;
            value += p.value * disc(pro.beta, t);
            // pro.A.list.remove(p);
          }
        }
        for (int i = 0; i < pro.A.list.size(); i++) {
          Parti p = pro.A.list.get(i);
          if (p.departure_time == t) {
            //						pro.A.list.remove(p);
            pro.Sample.addP(p);
          }
        }
        pro.A = pro.A.removeS();
        pro.A = pro.A.removeD(t);
        if (t == pro.ST[pro.l]) {
          //					System.out.println("&&&&&需要更新临界值了&&&&&");
          if (pro.Sample.list.isEmpty() == false) {
            pro.rho = pro.Sample.getThreshold(budget, l, pro.ll, pro.U, pro.L, pro.lam);
          }
          pro.l--;
          budget = budget * 2;
        }
        //				System.out.print("被选中的id为");
        //				pro.S.Pshow();
        //				System.out.println();
        //				System.out.print("Sample集为");
        //				pro.Sample.Pshow();
        //				System.out.println();
        //				System.out.print("候选集和为");
        //				pro.A.Pshow();
        //				System.out.println();

      }
      //			System.out.print("被选中的id为");
      //			pro.S.Pshow();
      //			System.out.println();
      System.out.println(value);
      System.out.println(pro.S.totalPay());
      out.println(
          j + "     " + pro.B + "     " + value + "      " + optValue + "      " + randomValue);
    }
    out.close();
  }