void WarmCallInfo::print() const {
  tty->print("%s : C=%6.1f P=%6.1f W=%6.1f S=%6.1f H=%6.1f -> %p",
             is_cold() ? "cold" : is_hot() ? "hot " : "warm",
             count(), profit(), work(), size(), compute_heat(), next());
  tty->cr();
  if (call() != NULL)  call()->dump();
}
// is_cold:  Return true if the node should never be inlined.
// This is true if any of the key metrics are extreme.
bool WarmCallInfo::is_cold() const {
  if (count()  <  WarmCallMinCount)        return true;
  if (profit() <  WarmCallMinProfit)       return true;
  if (work()   >  WarmCallMaxWork)         return true;
  if (size()   >  WarmCallMaxSize)         return true;
  return false;
}
Example #3
0
double Security::yearlyRate(const QDate &date1, const QDate &date2) {
    if(date1 > date2) return yearlyRate(date2, date1);
    if(date1 == date2) return 0.0;
    QMap<QDate, double>::const_iterator it_begin = quotations.begin();
    if(it_begin == quotations.end()) return 0.0;
    QDate curdate = QDate::currentDate();
    if(date1 >= curdate) {
        return pow(1 + (profit(date1, date2, true, true) / value(date1, true, true)), 1 / (yearsBetweenDates(date1, date2))) - 1;
    }
    if(date2 > curdate) {
        double rate1 = yearlyRate(date1, curdate);
        double rate2 = yearlyRate(curdate, date2);
        int days1 = date1.daysTo(curdate);
        int days2 = curdate.daysTo(date2);
        return ((rate1 * days1) + (rate2 * days2)) / (days1 + days2);
    }
    if(date2 < it_begin.key()) {
        return 0.0;
    }
    if(date1 < it_begin.key()) {
        return yearlyRate(it_begin.key(), date2);
    }
    QDate date1_q, date2_q;
    double q1 = getQuotation(date1, &date1_q);
    double q2 = getQuotation(date2, &date2_q);
    int days = date1.daysTo(date2);
    if(q1 != q2) {
        double q1_bak = q1;
        if(date1 != date1_q) {
            double rate = q1 / q2;
            int days1 = date1_q.daysTo(date1);
            q1 *= pow(rate, days1 / (days - days1));
        }
        if(date2 != date2_q) {
            double rate = q2 / q1_bak;
            int days2 = date2_q.daysTo(date2);
            q2 *= pow(rate, days2 / (days - days2));
        }
    }
    Income *trans = dividends.first();
    while(trans && trans->date() <= date2) {
        if(trans->date() >= date1) {
            double s = shares(trans->date());
            if(s > 0.0) q2 += trans->income() / s;
        }
        trans = dividends.next();
    }
    double shares_change = 0.0;
    ReinvestedDividend *rediv = reinvestedDividends.first();
    while(rediv && rediv->date <= date2) {
        if(rediv->date >= date1) {
            double s = shares(rediv->date);
            if(s > 0.0) shares_change += rediv->shares / (s - rediv->shares);
        }
        rediv = reinvestedDividends.next();
    }
    double change = q2 / q1 + shares_change;
    return pow(change, 1 / yearsBetweenDates(date1, date2)) - 1;
}
// is_hot:  Return true if the node should be inlined immediately.
// This is true if any of the key metrics are extreme.
bool WarmCallInfo::is_hot() const {
  assert(!is_cold(), "eliminate is_cold cases before testing is_hot");
  if (count()  >= HotCallCountThreshold)   return true;
  if (profit() >= HotCallProfitThreshold)  return true;
  if (work()   <= HotCallTrivialWork)      return true;
  if (size()   <= HotCallTrivialSize)      return true;
  return false;
}
// compute_heat:
float WarmCallInfo::compute_heat() const {
  assert(!is_cold(), "compute heat only on warm nodes");
  assert(!is_hot(),  "compute heat only on warm nodes");
  int min_size = MAX2(0,   (int)HotCallTrivialSize);
  int max_size = MIN2(500, (int)WarmCallMaxSize);
  float method_size = (size() - min_size) / MAX2(1, max_size - min_size);
  float size_factor;
  if      (method_size < 0.05)  size_factor = 4;   // 2 sigmas better than avg.
  else if (method_size < 0.15)  size_factor = 2;   // 1 sigma better than avg.
  else if (method_size < 0.5)   size_factor = 1;   // better than avg.
  else                          size_factor = 0.5; // worse than avg.
  return (count() * profit() * size_factor);
}
Example #6
0
int algo(int N, int T, char* model,char* prob,char* action){       

    //int N=4;    
    //int T=2;

    //double* v = (double*)calloc(N + (N+1) * (N+1) + T*(N+1),sizeof(double));
    /*double* dk      =v;
    double* pr      = v + N;
    double* MAXrev  = v + N + (N+1) * (N+1);*/

    double* dk=(double*)calloc(N,sizeof(double)); 
    double* MAXrev = (double*)calloc(T*(N+1), sizeof(double));    
    double* p = (double*)calloc((N+1) * (N+1),sizeof(double));    
    //char* act = (char*)calloc(1000000,sizeof(char));    
    int* path = (int*)calloc(T*(N+1), sizeof(int));
    //for(int i=0;i< T*(N+1);i++) printf("%g\n",path[i] );
    
    

    if(strcmp(prob, "squareroot") == 0){
        if ( calcDK(N,dk) != 0 ) return 0; 
    }
    else{
        //no other price impact model implemented
    }

    if(strcmp(model, "squareinverse") == 0){
        if ( calcPR(p,N) != 0 ) return 0;
    }
    else{
        //no other probability distributed implemented
    }

    if ( opt(N,T,p,MAXrev,path,dk) != 0 ) return 0;        
    if ( profit(N,T,p,MAXrev,path,dk,action) != 0 ) return 0;    

    //free(v);
    free(dk);
    free(p);
    free(path);
    return 0;
}
Example #7
0
int main(int argc, char *argv[])
{
	gene *g;
	int gsize, i;
	
	i = 0;
	
    if (argc != 2) {
        fprintf(stderr, "Usage: %s filename\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    
    if (!read_input(argv[1], &g, &gsize)) {
        fprintf(stderr, "Can't open file %s\n", argv[1]);
        exit(EXIT_FAILURE);
    }

#ifdef DEBUG
	printf("Genes (unsorted):\n");
    for (i = 0; i < gsize; i++) {
		printf("%d %d %d\n", g[i].start, g[i].finish, g[i].weight);
	}
#endif

	qsort(g, gsize, sizeof(gene), compare_genes);

#ifdef DEBUG
	printf("Genes (sorted):\n");
    for (i = 0; i < gsize; i++) {
		printf("%d %d %d\n", g[i].start, g[i].finish, g[i].weight);
	}
#endif

    printf("%d\n", profit(g, gsize));
    
    free(g);
        
    return 0;
}
Example #8
0
int
main()
{
    IloEnv env;
    try {
        NumMatrix cost(env, nbMonths);
        cost[0]=IloNumArray(env, nbProducts, 110.0, 120.0, 130.0, 110.0, 115.0);
        cost[1]=IloNumArray(env, nbProducts, 130.0, 130.0, 110.0,  90.0, 115.0);
        cost[2]=IloNumArray(env, nbProducts, 110.0, 140.0, 130.0, 100.0,  95.0);
        cost[3]=IloNumArray(env, nbProducts, 120.0, 110.0, 120.0, 120.0, 125.0);
        cost[4]=IloNumArray(env, nbProducts, 100.0, 120.0, 150.0, 110.0, 105.0);
        cost[5]=IloNumArray(env, nbProducts,  90.0, 100.0, 140.0,  80.0, 135.0);

        // Variable definitions
        IloNumVarArray produce(env, nbMonths, 0, IloInfinity);
        NumVarMatrix   use(env, nbMonths);
        NumVarMatrix   buy(env, nbMonths);
        NumVarMatrix   store(env, nbMonths);
        IloInt i, p;
        for (i = 0; i < nbMonths; i++) {
            use[i]   = IloNumVarArray(env, nbProducts, 0, IloInfinity);
            buy[i]   = IloNumVarArray(env, nbProducts, 0, IloInfinity);
            store[i] = IloNumVarArray(env, nbProducts, 0, 1000);
        }
        IloExpr profit(env);

        IloModel model(env);

        // For each type of raw oil we must have 500 tons at the end
        for (p = 0; p < nbProducts; p++) {
            store[nbMonths-1][p].setBounds(500, 500);
        }

        // Constraints on each month
        for (i = 0; i < nbMonths; i++) {
            // Not more than 200 tons of vegetable oil can be refined
            model.add(use[i][v1] + use[i][v2] <= 200);

            // Not more than 250 tons of non-vegetable oil can be refined
            model.add(use[i][o1] + use[i][o2] + use[i][o3] <= 250);

            // Constraints on food composition
            model.add(3 * produce[i] <=
                      8.8 * use[i][v1] + 6.1 * use[i][v2] +
                      2   * use[i][o1] + 4.2 * use[i][o2] + 5 * use[i][o3]);
            model.add(8.8 * use[i][v1] + 6.1 * use[i][v2] +
                      2   * use[i][o1] + 4.2 * use[i][o2] + 5 * use[i][o3]
                      <= 6 * produce[i]);
            model.add(produce[i] == IloSum(use[i]));

            // Raw oil can be stored for later use
            if (i == 0) {
                for (IloInt p = 0; p < nbProducts; p++)
                    model.add(500 + buy[i][p] == use[i][p] + store[i][p]);
            }
            else {
                for (IloInt p = 0; p < nbProducts; p++)
                    model.add(store[i-1][p] + buy[i][p] == use[i][p] + store[i][p]);
            }

            // Logical constraints
            // The food cannot use more than 3 oils
            // (or at least two oils must not be used)
            model.add((use[i][v1] == 0) + (use[i][v2] == 0) + (use[i][o1] == 0) +
                      (use[i][o2] == 0) + (use[i][o3] == 0) >= 2);

            // When an oil is used, the quantity must be at least 20 tons
            for (p = 0; p < nbProducts; p++)
                model.add((use[i][p] == 0) || (use[i][p] >= 20));

            // If products v1 or v2 are used, then product o3 is also used
            model.add(IloIfThen(env, (use[i][v1] >= 20) || (use[i][v2] >= 20),
                                use[i][o3] >= 20));

            // Objective function
            profit += 150 * produce[i] - IloScalProd(cost[i], buy[i]) -
                      5 * IloSum(store[i]);
        }

        // Objective function
        model.add(IloMaximize(env, profit));

        IloCplex cplex(model);

        if (cplex.solve()) {
            cout << "Solution status: " << cplex.getStatus() << endl;
            cout << " Maximum profit = " << cplex.getObjValue() << endl;
            for (IloInt i = 0; i < nbMonths; i++) {
                IloInt p;
                cout << " Month " << i << " " << endl;
                cout << "  . buy   ";
                for (p = 0; p < nbProducts; p++) {
                    cout << cplex.getValue(buy[i][p]) << "\t ";
                }
                cout << endl;
                cout << "  . use   ";
                for (p = 0; p < nbProducts; p++) {
                    cout << cplex.getValue(use[i][p]) << "\t ";
                }
                cout << endl;
                cout << "  . store ";
                for (p = 0; p < nbProducts; p++) {
                    cout << cplex.getValue(store[i][p]) << "\t ";
                }
                cout << endl;
            }
        }
        else {
            cout << " No solution found" << endl;
        }
    }
    catch (IloException& ex) {
        cerr << "Error: " << ex << endl;
    }
    catch (...) {
        cerr << "Error" << endl;
    }
    env.end();
    return 0;
}
Example #9
0
double Security::profit(const QDate &date1, const QDate &date2, bool estimate, bool no_scheduled_shares) {
    return profit(date2, estimate, no_scheduled_shares) - profit(date1, estimate, no_scheduled_shares);
}