Exemple #1
0
bool Borg::Ship::move(int warp, Destination d) {
    if (warp <= _maxWarp && d != _location && isStable()) {
        _location = d;
        return true;
    }
    return false;
}
Exemple #2
0
Fichier : k.cpp Projet : mayah/ICPC
pair<double, double> solve(const int* input) {
	vector<point> points;
	for (int i = 0; i < 18; i+=3) {
		points.push_back(makePoint(input[i+0], input[i+1], input[i+2]));
	}
	points.push_back(calculateTwoTetrahedraCenter(points[0],points[1],points[2],points[3],points[4]));
	
	double minHeight = 100000.0;
	double maxHeight = -1.0;
	for (int i = 0; i < ROTATION_SIZE; i++) {
		vector<point> rotated;
		for (int j = 0; j < POINT_SIZE; j++) {
			rotated.push_back(points[ROTATION[i][j]]);
		}
		if (!normalizePosition(rotated)) {
			continue;
		}
		
		if (isStable(rotated)) {
			minHeight = min(minHeight, rotated[5][2]);
			maxHeight = max(maxHeight, rotated[5][2]);
		}
	}
	
	return make_pair(minHeight, maxHeight);
}
void Balancer::startBalacing()
{
    //test if battery has recovered after last balancing
    if(!isStable(balancerStartStableCount))
        return;

    minCell_ = getCellMinV();
    AnalogInputs::ValueType vmin = getV(minCell_);

    //test if we can still discharge
    bool off = true;
    if(vmin >= ProgramData::currentProgramData.getVoltagePerCell(ProgramData::VDischarge)) {
        for(int i = 0; i < cells_; i++) {
            //save voltage values
            Von_[i] = Voff_[i] = getV(i);
            if(Von_[i] - vmin > settings.balancerError_)
                off = false;
        }
    }

    savedVon_ = false;
    startBalanceTime_ = timer.getMiliseconds();
    if(off) {
        endBalancing();
    } else {
        setBalance(calculateBalance());
    }
}
Exemple #4
0
bool Federation::Ship::move(int warp, Destination d) {
	if (warp <= getMaxWarp() && d != _location && isStable()) {
		_location = d;
		return true;
	}
	return false;
}
Exemple #5
0
void Balancer::startBalacing()
{
    //test if battery has recovered after last balancing
    if(!isStable(balancerStartStableCount) || !AnalogInputs::isOutStable())
        return;

    if(minCell < 0) {
        minCell = getCellMinV();
    }
    AnalogInputs::ValueType vmin = getV(minCell);

    //test if we can still discharge
    bool off = true;
    AnalogInputs::ValueType VdisMin =  ProgramData::currentProgramData.getVoltagePerCell(ProgramData::VDischarge);
    for(int i = 0; i < cells; i++) {
        //save voltage values
        AnalogInputs::ValueType v = getV(i);
        if(v < VdisMin) {
            off = true;
            break;
        }
        if(v > vmin) {
            off = false;
        }
        Von_[i] = Voff_[i] = v;
    }

    savedVon = false;
    startBalanceTimeSecondsU16_ = Time::getSecondsU16();
    if(off) {
        endBalancing();
    } else {
        setBalance(calculateBalance());
    }
}
Exemple #6
0
void		Borg::Ship::checkCore() {
  if (_core)
    {
      if (isStable())
	say("Everything is in order.");
      else
	say("Critical failure imminent.");
    }
}
int main(int argc, char *argv[])
{
    FILE *ufp = NULL, *sfp = NULL;
    item ublock[MAX_SIZE], sblock[MAX_SIZE];
    int itemsRead = 1, i = 0, stable = FALSE;

    // check if the user has given the correct arguments
    if (argc != 3){
        printUsage();
        exit(1);
    }

    else{
        printf("Unsorted file: %s and sorted file: %s\n", argv[1], argv[2]); 
    }

    // clear the arrays
    memset(ublock, 0, sizeof(item) * MAX_SIZE);
    memset(sblock, 0, sizeof(item) * MAX_SIZE);
    
    // open the files
    ufp = fopen(argv[1], "r"); // unsorted file
    sfp = fopen(argv[2], "r"); // sorted file
    if (ufp == NULL || sfp == NULL){ // error checking
        printf("Failed to open one of the files.\n");
        exit(1);
    }

    // read from unsorted list
    itemsRead = fscanf(ufp, "%d %s", &ublock[i].a, ublock[i].b);
    while (itemsRead > 1 && i < MAX_SIZE){ // should be always reading 2 values each call to fscanf()
        i++;
        itemsRead = fscanf(ufp, "%d %s", &ublock[i].a, ublock[i].b);
    }

    // read from sorted list
    i = 0;
    itemsRead = fscanf(sfp, "%d %s", &sblock[i].a, sblock[i].b);
    while (itemsRead > 1 && i < MAX_SIZE){
        i++;
        itemsRead = fscanf(sfp, "%d %s", &sblock[i].a, sblock[i].b);
    }

    stable = isStable(ublock, sblock, 0, i - 1);
    printf("Stable: %s\n", (stable) ? "TRUE" : "FALSE");

    fclose(ufp);
    fclose(sfp);

    return EXIT_SUCCESS;
}
Exemple #8
0
int
stabilize(float *frameIn, int npoles)
{
	long stable=0;
	float frameOut[MAXFRAME];
	for(int i=0; i<npoles; i++)
		frameOut[i] = -frameIn[npoles+3-i];
	if(!(stable = isStable(frameOut, npoles))) {
		correct(frameIn, npoles, frameOut);
		for (int n = 0; n < npoles; ++n)
			frameIn[n+4] = frameOut[n];
	}
	return stable;
}
Strategy::statusType Balancer::doStrategy()
{
    if(done_)
        return COMPLETE;
    if(isStable()) {
        if(balance_ == 0) {
            startBalacing();
        } else {
            trySaveVon();
            uint8_t balance = calculateBalance();
            if((balance_ & (~balance)) || getBalanceTime() > maxBalanceTime) {
                setBalance(0);
            }
        }
    }
    return RUNNING;
}
Strategy::statusType TheveninCharge::doStrategy()
{
    bool stable;
    bool isendVout = isEndVout();
    uint16_t oldValue = smps.getValue();

    stable = isStable() || isendVout;
    //test for charge complete
    if(theveninMethod.isComlete(isendVout, oldValue)) {
        smps.powerOff(SMPS::CHARGING_COMPLETE);
        return COMPLETE;
    }

    if(stable) {
        uint16_t value = theveninMethod.calculateNewValue(isendVout, oldValue);
        if(value != oldValue)
            smps.setValue(value);
    }
    return RUNNING;
}
void Balancer::startBalacing()
{
    //test if battery has recovered after last balancing
    if(!isStable(balancerStartStableCount) || !AnalogInputs::isOutStable())
        return;

    if(minCell < 0) {
        minCell = getCellMinV();
    }
    AnalogInputs::ValueType vmin = getV(minCell);

    //test if we can still discharge
    bool off = true;
    AnalogInputs::ValueType VdisMin =  ProgramData::battery.Vd_per_cell;
    for(uint8_t i = 0; i < MAX_BALANCE_CELLS; i++) {
        if(AnalogInputs::connectedBalancePortCells & (1<<i)) {
            //save voltage values
            AnalogInputs::ValueType v = getV(i);
            if(v < VdisMin) {
                off = true;
                break;
            }
            if(v > vmin) {
                off = false;
            }
            Von_[i] = Voff_[i] = v;
        }
    }
    LogDebug("off:", off);

    savedVon = false;
    startBalanceTimeSecondsU16_ = Time::getSecondsU16();
    if(off) {
        endBalancing();
    } else {
        setBalance(calculateBalance());
    }
}
Exemple #12
0
std::vector<Move> Solver::solve()
{
	if (!isStable())
		return std::vector<Move>();

	for (int r = 0; r < 10; r++) {
		std::vector<Move> currentNode = createRandomNode();
		while (true) {
			if (score(currentNode) == 0) {
				return currentNode;
			}

			std::vector< std::vector<Move> > l = getNeighbors(currentNode);
			int nextEval = -INF;
			std::vector<Move> nextNode = std::vector<Move>();
			for (int i = 0; i < (int) l.size(); i++) {
				if (score(l[i]) > nextEval) {
					nextNode = l[i];
					nextEval = score(l[i]);
				}
			}

			if (nextEval <= score(currentNode)) {
				if (score(currentNode) > -3 * (int) blocks.size()) {
					//print(currentNode);
					return currentNode;
				}
				break;
			}

			currentNode = nextNode;
		}
	}

	return std::vector<Move>();
}
bool AnalogInputs::isOutStable()
{
    return isStable(AnalogInputs::VoutBalancer) && isStable(AnalogInputs::Iout) && Balancer::isStable();
}
Exemple #14
0
bool NetioHandler::isAllStable() {
  for (uint32_t i=0; i<m_monitors.size(); ++i){
    if ( !isStable(i) ) return false;
  }
  return true;
}