Example #1
0
/*
  This is supposed to cut the cache size down by about 25% in a
  minute once the application becomes idle, to let any inserted pixmap
  remain in the cache for some time before it becomes a candidate for
  cleaning-up, and to not cut down the size of the cache while the
  cache is in active use.

  When the last pixmap has been deleted from the cache, kill the
  timer so Qt won't keep the CPU from going into sleep mode.
*/
void QPMCache::timerEvent(QTimerEvent *)
{
    int mc = maxCost();
    bool nt = totalCost() == ps;
    setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
    setMaxCost(mc);
    ps = totalCost();

    QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin();
    while (it != cacheKeys.end()) {
        if (!contains(it.value())) {
            releaseKey(it.value());
            it = cacheKeys.erase(it);
        } else {
            ++it;
        }
    }

    if (!size()) {
        killTimer(theid);
        theid = 0;
    } else if (nt != t) {
        killTimer(theid);
        theid = startTimer(nt ? 10000 : 30000);
        t = nt;
    }
}
Example #2
0
int main() {
  printf("%f == 400\n", totalCost(1, 0, 0));
  printf("%f == 1000\n", totalCost(0, 1, 0));
  printf("%f == 600\n", totalCost(0, 0, 1));
  printf("%f == 2000\n", totalCost(1, 1, 1));
  printf("%f == 4000\n", totalCost(2, 2, 2));
  return 0;
}
Example #3
0
int main() {
    printf("%f == %f\n", 20 * 0.22 + 14 * 0.33, beadsCost(20, 14));
    printf("%f == %f\n", 24 * 0.14, threadCost(24));
    printf("%f == %f\n", 24 * 0.14, threadCost(20));
    printf("%f == %f\n", 30 * 0.14, threadCost(30));
    printf("%f == %f\n", 24 * 0.14, threadCost(23));
    printf("%f == %f\n", 25 * 0.14, threadCost(25));
    printf("%f == %f\n", 20 * 0.22 + 14 * 0.33 + 24 * 0.14, totalCost(20, 14, 24));
    printf("%f == %f\n", 20 * 0.22 + 14 * 0.33 + 24 * 0.14, totalCost(20, 14, 20));
    printf("%f == %f\n", 20 * 0.22 + 14 * 0.33 + 30 * 0.14, totalCost(20, 14, 30));
    return 0;
}
Example #4
0
QT_BEGIN_INCLUDE_NAMESPACE
#include "qpixmapcache.moc"
QT_END_INCLUDE_NAMESPACE

/*
  This is supposed to cut the cache size down by about 80-90% in a
  minute once the application becomes idle, to let any inserted pixmap
  remain in the cache for some time before it becomes a candidate for
  cleaning-up, and to not cut down the size of the cache while the
  cache is in active use.

  When the last pixmap has been deleted from the cache, kill the
  timer so Qt won't keep the CPU from going into sleep mode.
*/

void QPMCache::timerEvent(QTimerEvent *)
{
    int mc = maxCost();
    bool nt = totalCost() == ps;
    setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
    setMaxCost(mc);
    ps = totalCost();

    QHash<QString, qint64>::iterator it = cacheKeys.begin();
    while (it != cacheKeys.end()) {
        if (!contains(it.value())) {
            it = cacheKeys.erase(it);
        } else {
            ++it;
        }
    }

    if (!size()) {
        killTimer(id);
        id = 0;
    } else if (nt != t) {
        killTimer(id);
        id = startTimer(nt ? 10000 : 30000);
        t = nt;
    }
}
Example #5
0
void QPMCache::timerEvent(QTimerEvent *)
{
    bool nt = totalCost() == ps;
    if (!flushDetachedPixmaps(nt)) {
        killTimer(theid);
        theid = 0;
    } else if (nt != t) {
        killTimer(theid);
        theid = startTimer(nt ? soon_time : flush_time);
        t = nt;
    }
}
Example #6
0
/*
  This is supposed to cut the cache size down by about 25% in a
  minute once the application becomes idle, to let any inserted pixmap
  remain in the cache for some time before it becomes a candidate for
  cleaning-up, and to not cut down the size of the cache while the
  cache is in active use.

  When the last detached pixmap has been deleted from the cache, kill the
  timer so Qt won't keep the CPU from going into sleep mode. Currently
  the timer is not restarted when the pixmap becomes unused, but it does
  restart once something else is added (i.e. the cache space is actually needed).

  Returns \c true if any were removed.
*/
bool QPMCache::flushDetachedPixmaps(bool nt)
{
    int mc = maxCost();
    setMaxCost(nt ? totalCost() * 3 / 4 : totalCost() -1);
    setMaxCost(mc);
    ps = totalCost();

    bool any = false;
    QHash<QString, QPixmapCache::Key>::iterator it = cacheKeys.begin();
    while (it != cacheKeys.end()) {
        if (!contains(it.value())) {
            releaseKey(it.value());
            it = cacheKeys.erase(it);
            any = true;
        } else {
            ++it;
        }
    }

    return any;
}
Example #7
0
	void exec( ) throw( general_error )
	{
		// get values
		double rating = (double) as_number("machine_rating");
		double diameter = (double)as_number("rotor_diameter");
		double hubHt = (double)as_number("hub_height");
		int nTurb = as_integer("number_of_turbines");
		double voltage = (double)as_number("interconnect_voltage");
		double distInter = (double)as_number("distance_to_interconnect");
		SiteTerrain terrain = (SiteTerrain) as_integer("site_terrain");
		TurbineLayout layout = (TurbineLayout)as_integer("turbine_layout");
		SoilCondition soil = (SoilCondition)as_integer("soil_condition");

		double farmSize = cm_windbos::farmSize(rating, nTurb);

		int constructionTime = (int)as_number("construction_time");
		double buildingSize = (double)as_number("om_building_size");
		double temporary = (double)as_number("quantity_test_met_towers");
		double permanent = (double)as_number("quantity_permanent_met_towers");
		int weatherDelayDays = (int)as_number("weather_delay_days");
		int craneBreakdowns = (int)as_number("crane_breakdowns");
		int accessRoadEntrances = (int)as_number("access_road_entrances");


		double tcc = (double)as_number("turbine_capital_cost");
		double topMass = (double)as_number("tower_top_mass");
		int deliveryAssistRequired = as_integer("delivery_assist_required");
		int padMountTransformer = as_integer("pad_mount_transformer_required");
		int newSwitchyardRequired = as_integer("new_switchyard_required");
		double rockTrenchingLength = (double)as_number("rock_trenching_required");
		double thermalBackfill = (double)as_number("mv_thermal_backfill");
		double overheadCollector = (double)as_number("mv_overhead_collector");
		double performanceBond = (double)as_number("performance_bond");
		double contingency = (double)as_number("contingency");
		double warranty = (double)as_number("warranty_management");
		double useTax = (double)as_number("sales_and_use_tax");
		double overhead = (double)as_number("overhead");
		double profitMargin = (double)as_number("profit_margin");
		double developmentFee = (double)as_number("development_fee");
		double transportDist = (double)as_number("turbine_transportation");


		// run model (execute functions)
		ssc_number_t output = totalCost(rating, diameter, hubHt, nTurb, voltage, distInter, terrain, layout, soil,
			farmSize, tcc, topMass, constructionTime, buildingSize, temporary, permanent, weatherDelayDays, craneBreakdowns, accessRoadEntrances,
			deliveryAssistRequired, padMountTransformer, newSwitchyardRequired, rockTrenchingLength, thermalBackfill, overheadCollector,
			performanceBond, contingency, warranty,	useTax, overhead, profitMargin,	developmentFee, transportDist);

		// assign outputs
		assign( "project_total_budgeted_cost", var_data(output) );
	}
Example #8
0
ompl::base::Cost ompl::base::OptimizationObjective::averageStateCost(unsigned int numStates) const
{
    StateSamplerPtr ss = si_->allocStateSampler();
    State *state = si_->allocState();
    Cost totalCost(this->identityCost());

    for (unsigned int i = 0 ; i < numStates ; ++i)
    {
        ss->sampleUniform(state);
        totalCost = this->combineCosts(totalCost, this->stateCost(state));
    }

    si_->freeState(state);

    return Cost(totalCost.v / (double)numStates);
}
 int minCostClimbingStairs(vector<int>& cost) {
     if (cost.size() <= 1)
         return 0;
     
     vector<int> totalCost(cost.size() + 1, 0);
     totalCost[0] = 0;
     totalCost[1] = 0;
     
     for (int i = 2; i <= cost.size(); ++i) {
         totalCost[i] = totalCost[i-1] + cost[i-1];
         if (totalCost[i] > totalCost[i-2] + cost[i-2])
             totalCost[i] = totalCost[i-2] + cost[i-2];
     }
     
     return totalCost[cost.size()];
 }
Example #10
0
int main ()
{
    int salesID, count, prodID, quantity, weight, totweight, distance; 
    float discount, price, totprodcost, tax, ship, totcost;
    cout.setf(ios::fixed, ios::floatfield); // Sets the default output to 2 places
    cout.setf(ios::showpoint);
    cout.precision(2);
    count=0;
    cout << "         Blivet Manufacturing - Sales Report" << endl << endl;
    cout << "Person" << " " << "Prod" << " " << "Price";
    cout << " " << "Qnt" << " " << "Wght" << " " << "Dist";
    cout << " " << "Ship" << "    " << "TPC" << "   " << "Tax";
    cout << "   " << "TotCost" << endl;
    char salesnames[ 7 ][ 10 ] = {"daBoss\0","Fred\0","Bob\0","Mary\0","Scott\0",
                           "Susan\0","Jack\0"};
    ifstream inData;
    ship=0.00;
    totcost=0.00;
    tax=0.00;
    inData.open( "datafile.dat");
    inData >> salesID >> prodID >> price >> discount >> quantity >> weight >> distance;
    while (inData) //End of File controlled loop
    {   
        calcShipCost (quantity, weight, distance, ship);
        totprodcost= calcProdCost( quantity, price, discount);
        totalCost( totprodcost, ship, tax, totcost);
        
        cout << setw (6) << salesnames[ salesID] << setw (4) << prodID; // Properly formatted output
        cout << setw (7) << price << setw (4) << quantity;
        cout << setw (6) << weight << setw (4) << distance;
        cout << setw (6) << ship << setw (8) << totprodcost;
        cout << setw (7) << tax << setw (8) << totcost << endl;
        inData >> salesID >> prodID >> price >> discount >> quantity >> weight >> distance;
        count++;
    }
    cout << "Total Number of Records Processed: " << count << endl; // total number of records processed
        system ("Pause");
}