예제 #1
0
파일: game_q.hpp 프로젝트: cernoch/sequoia
const MCGame_f* QUndetGame<TFormula, TMove, _player>::add_subgame(const TMove* move,
								  const MCGame_f* game) {
    if (game->get()->outcome() == _player) {
	if (is_pointmove<TMove>::value && move == NULL) { // compiler will optimize this away for non-pointmoves
	    /*
	     * The current player must not use the NULL move for their advantage.
	     * An example where this may happen is testing whether the graph is
	     * a complete graph:  ALL x ALL y adj(x, y).
	     * If there is a non-vertex in the PAST, the game for adj(x,y)
	     * will return FALSE for the NULL move (due to the graph separator
	     * property).  Returning FALSE here would be wrong, when there is
	     * no vertex left to come.  We have to wait until this move is concrete.
	     */
	    DPRINTLN(" --> re-check this "
		    << formula()->variable()->identifier()
		    << " later (when concrete)!");
	    QUndetGame<TFormula, TMove, _player>::set_subgame(NULL, game);
	    return NULL;
	} else {
                DPRINTLN(" --> determines!");
                delete this;
		return game;
	}
    }
    if (game->get()->outcome() == MCGame::opponent<_player>::value) {
	    DPRINTLN(" --> ignore this "
		    << formula()->variable()->identifier()<< "!");
	    delete game;
	    return NULL;
    }
    DPRINTLN(" --> re-check this "
            << formula()->variable()->identifier() << " later!");
    QUndetGame<TFormula, TMove, _player>::set_subgame(move, game);
    return NULL;
}
예제 #2
0
파일: Parser.cpp 프로젝트: SOM-st/SOMpp
void Parser::ifTrueMessage(MethodGenerationContext* mgenc) {
    size_t false_block_pos = bcGen->EmitJUMP_IF_FALSE(mgenc);
    if (sym == NewBlock) {
        inlinedBlock(mgenc);
    } else {
        formula(mgenc);
        VMSymbol* msg = GetUniverse()->SymbolFor("value");
        mgenc->AddLiteralIfAbsent(msg);
        bcGen->EmitSEND(mgenc, msg);
    }
    
    size_t after_pos = bcGen->EmitJUMP(mgenc);
    mgenc->PatchJumpTarget(false_block_pos);
    
    if (sym == Keyword) {
        StdString ifFalse = keyword();
        assert(ifFalse == "ifFalse:");
        if (sym == NewBlock) {
            inlinedBlock(mgenc);
        } else {
            formula(mgenc);
            VMSymbol* msg = GetUniverse()->SymbolFor("value");
            mgenc->AddLiteralIfAbsent(msg);
            bcGen->EmitSEND(mgenc, msg);
        }
    } else {
        VMSymbol* global = GetUniverse()->SymbolFor("nil");
        mgenc->AddLiteralIfAbsent(global);
        
        bcGen->EmitPUSHGLOBAL(mgenc, global);
    }
    mgenc->PatchJumpTarget(after_pos);
    
    assert(sym != Keyword);
}
예제 #3
0
파일: Parser.cpp 프로젝트: SOM-st/SOMpp
void Parser::keywordMessage(MethodGenerationContext* mgenc, bool super) {
    StdString kw = keyword();
    
    // special compilation for ifTrue and ifFalse
    if (!super && kw == "ifTrue:") {
        ifTrueMessage(mgenc);
        return;
    } else if (!super && kw == "ifFalse:") {
        ifFalseMessage(mgenc);
        return;
    }
    formula(mgenc);
    while (sym == Keyword) {
        kw.append(keyword());
        formula(mgenc);
    }

    VMSymbol* msg = GetUniverse()->SymbolFor(kw);

    mgenc->AddLiteralIfAbsent(msg);

    if (super)
        bcGen->EmitSUPERSEND(mgenc, msg);
    else
        bcGen->EmitSEND(mgenc, msg);

}
예제 #4
0
void *look_for_min(void *threadid){
    
    long tid;
    tid = (long) threadid;
    
    long start, end;
    long j, k;
    
    start = tid*M/NUM_THREADS + 1;
    end = start + M/NUM_THREADS -1;

    for(j=start; j<end; j++){
        long sum = 0, differences = 0;
        for(k=j+1; k<M; k++){
            sum = formula(j) + formula(k);
            differences = formula(k) - formula(j);
            if(is_pentagonal(sum) && is_pentagonal(differences))
                if(sum - differences <= minD){
                    pthread_mutex_lock(&mutex1);
                    minD = sum - differences;
                    pthread_mutex_unlock(&mutex1);
                }
        }
        
        //printf("%d\n", formula(i));
    }
    printf("%d\n", minD);
    pthread_exit(NULL);
}
예제 #5
0
const char *CFormula::GetFunctionText(const char *name)
{
	for (int i=0; i<formula()->mFunction.GetSize(); i++)
	{
		if (!formula()->mFunction[i].func.Compare(name))
			return formula()->mFunction[i].func_text.GetString();
	}
	return "";
}
예제 #6
0
    void test_formula3()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell(xlnt::cell_reference(1, 1));

        xlnt_assert(!cell.has_formula());
        xlnt_assert_throws_nothing(cell.formula(""));
        xlnt_assert(!cell.has_formula());
        cell.formula("=42");
        xlnt_assert(cell.has_formula());
        xlnt_assert_equals(cell.formula(), "42");
        cell.clear_formula();
        xlnt_assert(!cell.has_formula());
    }
예제 #7
0
파일: mktable.c 프로젝트: xshang/pandaseq
static void
buildmatrix(
	FILE *header,
	FILE *source,
	char *name,
	double (*formula) (double,
		double)) {
	int i, j;
	fprintf(header, "extern double %s[][%d];\n", name, PHREDMAX + 1);
	fprintf(source, "double %s[][%d] = {\n", name, PHREDMAX + 1);
	for (i = 0; i <= PHREDMAX; i++) {
		if (i > 0) {
			fprintf(source, ", \n");
		}
		fprintf(source, "\t{");
		for (j = 0; j <= PHREDMAX; j++) {
			if (j > 0) {
				fprintf(source, ",");
			}

			fprintf(source, " %g", log(formula(PROBABILITY(i), PROBABILITY(j))));

		}
		fprintf(source, "}");
	}
	fprintf(source, "};\n");

}
예제 #8
0
QVariant SpreadSheetItem::data(int role) const
{
    if (role == Qt::EditRole || role == Qt::StatusTipRole)
        return formula();

    if (role == Qt::DisplayRole)
        return display();

    QString t = display().toString();
    bool isNumber = false;
    int number = t.toInt(&isNumber);

    if (role == Qt::TextColorRole) {
        if (!isNumber)
            return qVariantFromValue(QColor(Qt::black));
        else if (number < 0)
            return qVariantFromValue(QColor(Qt::red));
        return qVariantFromValue(QColor(Qt::blue));
    }

     if (role == Qt::TextAlignmentRole)
         if (!t.isEmpty() && (t.at(0).isNumber() || t.at(0) == '-'))
             return (int)(Qt::AlignRight | Qt::AlignVCenter);

     return QTableWidgetItem::data(role);
 }
예제 #9
0
QVariant Cell::display(const QString &data) const
{
    QString temp = (data.isEmpty())?formula():data;
    if (!isValidFormula(temp))
        return temp;

    QString aux = "((";
    for (int i=1; i<temp.length(); i++)
        if (temp[i] == '+')
            aux.append("))+((");
        else if (temp[i] == '-')
            aux.append("))-((");
        else if (temp[i] == '*')
            aux.append(")*(");
        else if (temp[i] == '/')
            aux.append(")/(");
        else if (temp[i] == '(')
            aux.append("(((");
        else if (temp[i] == ')')
            aux.append(")))");
        else
            aux.append(temp[i]);
    aux.append("))");

    if (!isValidFormula("=" + aux))
        return temp;
    QVariant result = computeFormula(aux, (SpreadSheet*)tableWidget());
    return result;
}
예제 #10
0
파일: parser.c 프로젝트: hellsale/ptex
static void
content (int endmark)
{
    while (c != EOF && c != endmark)
    {
        if (c == DOT)
        {
            release ('\\');
            c = next ();
            command (TEXT);
        }
        else if (c == DASHPAR || c == EQPAR
        || c == '-' || c == '=')
        {
            formula ();
            if (c == '-') /* TEMPORARY BUG FIX */
            {
                release ('-');
                c = next ();
            }
        }
        else if (c == '*') emphas ();
        else fill (TEXT);
        checkpar (endmark);
    }
}
예제 #11
0
CircleAreaModel::CircleAreaModel(
        const SpaceModel &space,
        const Id<AreaModel> &id,
        QObject *parent):
    AreaModel{AreaParser{formula()}.result(), space, id, parent}
{
    /*
    const auto& space_vars = this->space().space().variables();
    const auto& syms = area().symbols();
    GiNaC::symbol xv, x0, yv, y0, r;
    for(decltype(syms.size()) i = 0; i < syms.size(); i++)
    {
             if(syms[i].get_name() == "xv") xv = syms[i];
        else if(syms[i].get_name() == "yv") yv = syms[i];
        else if(syms[i].get_name() == "x0") x0 = syms[i];
        else if(syms[i].get_name() == "y0") y0 = syms[i];
        else if(syms[i].get_name() == "r") r = syms[i];
        else ISCORE_ABORT;
    }
    setSpaceMapping({{xv, space_vars[0].symbol()}, // xv -> x
                     {yv, space_vars[1].symbol()}}); // yv -> y

    iscore::FullAddressSettings x0_val, y0_val, r_val;
    x0_val.value = iscore::Value::fromVariant(200);
    y0_val.value = iscore::Value::fromVariant(200);
    r_val.value = iscore::Value::fromVariant(100);
    setParameterMapping({
                    {x0.get_name().c_str(), {x0, x0_val}},
                    {y0.get_name().c_str(), {y0, y0_val}},
                    {r.get_name().c_str(), {r, r_val}},
                });
                */
}
예제 #12
0
bool Spreadsheet::writeFile(const QString &fileName)
{
    QFile file(fileName);
    if(!file.open(QIODevice::WriteOnly))
    {
        QMessageBox::warning(   this
                              , tr("Spreadsheet")
                              , tr("Cannot write file %1:\n%2.")
                                .arg(file.fileName())
                                .arg(file.errorString()));
        return false;
    }

    QDataStream out(&file);
    out.setVersion(QDataStream::Qt_4_3);
    out << quint32(MagicNumber);

    QApplication::setOverrideCursor(Qt::WaitCursor);
    for(int row = 0; row < RowCount; ++row)
        for(int column = 0; column < ColumnCount; ++column)
        {
            QString str = formula(row, column);
            if(!str.isEmpty())
                out << quint16(row) << quint16(column) << str;
        }

    QApplication::restoreOverrideCursor();

    return true;
}
예제 #13
0
void Spreadsheet::sort(const SpreadsheetCompare &compare)
{
    QList<QStringList> rows;
    QTableWidgetSelectionRange range = selectedRange();
    int i;

    for(i = 0; i < range.rowCount(); ++i)
    {
        QStringList row;
        for(int j = 0; j < range.columnCount(); ++j)
            row.append(formula(range.topRow() + i, range.leftColumn() + j));

        rows.append(row);
    }


    qStableSort(rows.begin(), rows.end(), compare);

    for(i = 0; i < range.rowCount(); ++i)
    {
        for(int j = 0; j < range.columnCount(); ++j)
            setFormula(range.topRow() + i, range.leftColumn() + j, rows[i][j]);
    }

    clearSelection();
    somethingChanged();
}
//	VERSION  2A).  //
TRIANGLE* MarchingCubes(float mcMinX, float mcMaxX, float mcMinY, float mcMaxY, float mcMinZ, float mcMaxZ, 
							int ncellsX, int ncellsY, int ncellsZ, float minValue, 
							FORMULA formula, INTERSECTION intersection, int &numTriangles)
{
	//space is already defined and subdivided, staring with step 3
	//first initialize the points
	mp4Vector * mcDataPoints = new mp4Vector[(ncellsX+1)*(ncellsY+1)*(ncellsZ+1)];
	mpVector stepSize((mcMaxX-mcMinX)/ncellsX, (mcMaxY-mcMinY)/ncellsY, (mcMaxZ-mcMinZ)/ncellsZ);
	
	int YtimesZ = (ncellsY+1)*(ncellsZ+1);	//for extra speed
	for(int i=0; i < ncellsX+1; i++) {
		int ni = i*YtimesZ;						//for speed
		float vertX = mcMinX + i*stepSize.x;
		for(int j=0; j < ncellsY+1; j++) {
			int nj = j*(ncellsZ+1);				//for speed
			float vertY = mcMinY + j*stepSize.y;
			for(int k=0; k < ncellsZ+1; k++) {
				mp4Vector vert(vertX, vertY, mcMinZ + k*stepSize.z, 0);
				vert.val = formula((mpVector)vert);
   /*(step 3)*/ mcDataPoints[ni + nj + k] = vert;
			}
		}
	}
	//then run Marching Cubes (version 1A) on the data
	return MarchingCubes(ncellsX, ncellsY, ncellsZ, minValue, mcDataPoints, intersection, numTriangles);
}
예제 #15
0
 void
 loadArchitecture(const InitializerList& modules, size_t memorySize = 64) {
   ArchitectureFormula formula("riscv", modules);
   project = std::make_unique<ProjectModule>(formula, memorySize, "riscv");
   factories = project->getArchitectureAccess()
                   .getArchitecture()
                   .get()
                   .getNodeFactories();
 }
예제 #16
0
formularioHerr::formularioHerr(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	QImage formula("costo_herramienta.png");
	ui.label_11->setPixmap(QPixmap::fromImage(formula));
	ui.label_11->setScaledContents(true);
	connect(ui.comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(labelCombo(QString)));
	connect(ui.pushButton_3,SIGNAL(clicked()),this,SLOT(ayuda()));
}
예제 #17
0
QVariant PhysEqSolverItem::display() const {

    // avoid circular dependencies
    if (m_isResolving)
        return QVariant();
    m_isResolving = true;
    QVariant result = computeFormula(formula(), tableWidget(), this);
    m_isResolving = false;
    return result;
}
예제 #18
0
QVariant Cell::data(int role) const
{
    if (role == Qt::EditRole)
        return formula();
    else if (role == Qt::DisplayRole)
            return display();
    else if (role == Qt::TextAlignmentRole)
        return int(Qt::AlignLeft | Qt::AlignVCenter);
    else
        return QTableWidgetItem::data(role);
}
예제 #19
0
int main() {
	int num;
	scanf("%d", &num);
	if (num < 0) {
		printf("Digite numeros positivos!");
	}
	else {
		formula(&num);
	}
	return(0);
}
예제 #20
0
파일: 1155.cpp 프로젝트: arrows-1011/CPro
int formula(){
    int l,r;
    char c = *p++;
    if(isdigit(c)) return c-'0';
    if(isupper(c)) return (c == 'P' ? P : c == 'Q' ? Q : R);
    if(c == '-') return 2-formula();
    if(c == '('){
	l = formula();
	if(*p++ == '*'){
	    r = formula();
	    *p++;
	    return (l < r ? l : r);
	}else{
	    r = formula();
	    *p++;
	    return (l > r ? l : r);
	}  
    }
    return 0;
}
예제 #21
0
QVariant SpreadSheetItem::display() const
{
    // avoid circular dependencies
    if (isResolving)
        return QVariant();

    isResolving = true;
    QVariant result = computeFormula(formula(), tableWidget(), this);
    isResolving = false;
    return result;
}
예제 #22
0
void Rel_Body::rearrange() {
  assert(children().length()==1);

  skip_finalization_check++;
  formula()->rearrange();
  skip_finalization_check--;

  if(pres_debug) {
    fprintf(DebugFile, "\n=== Rearranged TREE ===\n");
    prefix_print(DebugFile);
  }
}
예제 #23
0
int main ( void )
{
	void displayDayOfWeek ( int n, struct date input);
	int dayOfWeek ( int n );
	int formula ( struct date input );

	printf ( "Please enter a date like yyyy/mm/dd (2013/09/12):  " );
	scanf ( "%i/%i/%i", &inPutDate.year, &inPutDate.month, &inPutDate.day );

	displayDayOfWeek ( dayOfWeek ( formula ( inPutDate) ), inPutDate );
	return 0;
}	
예제 #24
0
/* Triangle rasterization algorithm with optimizations
*/
void
draw_triangle_optimized(float x0, float y0, float x1, float y1, float x2, float y2,
    byte r, byte g, byte b)
{
	float xmin,xmax,ymin,ymax;
	float f20,f01, f12;
	float alpha,beta,gamma;
	float x,y;
	float off_f12, off_f20, off_f01;
	float x02,x10, x21, y20,y01, y12;
	
	//square around triangle in which all points are looked at
	xmin = min(x0,x1,x2);
	xmax = max(x0,x1,x2);
	ymin = min(y0,y1,y2);
	ymax = max(y0,y1,y2);
	
	f20 = formula(x2,y2, x0, y0, x1, y1);
	f01 = formula(x0,y0, x1, y1, x2, y2);
	f12 = formula(x1,y1, x2, y2, x0, y0);
	
	x02 = (x0-x2)/f20;
	x10 = (x1-x0)/f01;
	x21 = (x2-x1)/f12;

	y20 = (y2-y0)/f20;
	y01 = (y0-y1)/f01;
	y12 = (y1-y2)/f12;

	// calculations for offscreen point
 	off_f12 = formula(x1,y1, x2, y2, off_x, off_y);
	off_f20 = formula(x2,y2, x0, y0, off_x, off_y);
	off_f01 = formula(x0,y0, x1, y1, off_x, off_y);
	
	beta  = ( (y2 - y0)*xmin+(x0-x2)*ymin+x2*y0-y2*x0 ) / f20;
	gamma =	( (y0 - y1)*xmin+(x1-x0)*ymin+x0*y1-x1*y0 ) / f01;
	alpha = ( (y1 - y2)*xmin+(x2-x1)*ymin+x1*y2-x2*y1 ) / f12;

	
	// Loop through square and check if pixel is in triangle
	for (x = xmin; x < xmax; ++x)
	{	
		for (y = ymin; y < ymax; ++y)
		{
			
			// Pixel is in triangle
			if (alpha >= 0 && beta >= 0 && gamma >= 0){
				if((alpha > 0 || (f12*off_f12) > 0) && (beta > 0 || (f20*off_f20) > 0) && (gamma > 0 || (f01*off_f01) > 0)){
					PutPixel(x,y,r,g,b);
				}
			}
			beta  += x02;
			gamma += x10;
			alpha += x21;
		}
		beta  += y20 -(ymax-ymin)*x02;
		gamma += y01 -(ymax-ymin)*x10;
		alpha += y12 -(ymax-ymin)*x21;
	}
}
예제 #25
0
파일: EMModule.cpp 프로젝트: smtrat/smtrat
 Answer EMModule<Settings>::checkCore()
 {
     auto receivedFormula = firstUncheckedReceivedSubformula();
     while (receivedFormula != rReceivedFormula().end()) {
         FormulaT formula = receivedFormula->formula();
         if (receivedFormula->formula().propertyHolds(carl::PROP_CONTAINS_NONLINEAR_POLYNOMIAL)) {
             formula = mVisitor.visitResult(receivedFormula->formula(), eliminateEquationFunction);
         }
         if (formula.isFalse()) {
             receivedFormulasAsInfeasibleSubset(receivedFormula);
             return UNSAT;
         }
         if (!formula.isTrue()) {
             addSubformulaToPassedFormula(formula, receivedFormula->formula());
         }
         ++receivedFormula;
     }
     Answer ans = runBackends();
     if (ans == UNSAT)
         getInfeasibleSubsets();
     return ans;
 }
예제 #26
0
void SpreadSheet::evaluateCell( QTableWidgetItem *item, const QString &f, const QString &vars )
{
    QString formula( f );
    int row = sheet1->row(item);
    int col = sheet1->column(item);

    if ( formula[0] != '=' )
	    return;
    QString cn = cellName( row, col );
    formula = vars + "\n" + cn + "=" + formula.mid(1) + ";\n" +
	          "Application." + QString(sheet1->objectName()) + 
              ".setText(" + QString::number(row) +
	          ", " + QString::number(col) + ", String(" + cn + "));";
    interpreter->evaluate( formula );
}
예제 #27
0
formularioMaq::formularioMaq(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	QImage formula("costo_maq.png");
	ui.label_17->setPixmap(QPixmap::fromImage(formula));
	ui.label_17->setScaledContents(true);

	connect(ui.pushButton,SIGNAL(clicked()),this,SLOT(pathDialog()));
	connect(ui.doubleSpinBox_2,SIGNAL(valueChanged(double)),this,SLOT(calcularDepre(double)));
	connect(ui.spinBox,SIGNAL(valueChanged(int)),this,SLOT(calcularDepre2(int)));
	connect(ui.doubleSpinBox_2,SIGNAL(valueChanged(double)),this,SLOT(costo_hora(double)));
	connect(ui.spinBox_2,SIGNAL(valueChanged(int)),this,SLOT(costo_hora2(int)));
	connect(ui.spinBox,SIGNAL(valueChanged(int)),this,SLOT(costo_hora3(int)));
	connect(ui.pushButton_4,SIGNAL(clicked()),this,SLOT(ayuda()));
}
void Spreadsheet::copy()
{
    QTableWidgetSelectionRange range = selectedRange();
    QString str;

    for (int i = 0; i < range.rowCount(); ++i) {
        if (i > 0)
            str += "\n";
        for (int j = 0; j < range.columnCount(); ++j) {
            if (j > 0)
                str += "\t";
            str += formula(range.topRow() + i, range.leftColumn() + j);
        }
    }
    QApplication::clipboard()->setText(str);
}
예제 #29
0
	void Preprocessor::removeTrivialClauses(void)
	{
		SAT::CNF& formula(context().formula);
		formula.erase(std::remove_if(formula.begin(), formula.end(), [](SAT::Clause& clause) {
			for (auto itr = clause.begin();
				itr != clause.end();
				itr++)
			{
				if (itr + 1 != clause.end() && itr->getVariable() != (itr + 1)->getVariable())
					itr++;
				else
					return true;
			}
			return false;
		}
		), formula.end());
	}
예제 #30
0
파일: 1155.cpp 프로젝트: arrows-1011/CPro
int main(){
    int ans;
    char s[100];
    while(scanf("%s",s), s[0] != '.'){
	ans = 0; 
	for(P = 0 ; P < 3 ; P++){
	    for(Q = 0 ; Q < 3 ; Q++){
		for(R = 0 ; R < 3 ; R++){
		    p = s;
		    if(formula() == 2) ans++;
		}
	    }
	}
	printf("%d\n",ans);
    }
    return 0;
}