Example #1
0
File: smc.c Project: 69yuan/sd2snes
uint8_t smc_headerscore(snes_header_t* header) {
	uint8_t score=0;
	score += countAllASCII(header->maker, sizeof(header->maker));
	score += countAllASCII(header->gamecode, sizeof(header->gamecode));
	score += isFixed(header->fixed_00, sizeof(header->fixed_00), 0x00);
	score += countAllJISX0201(header->name, sizeof(header->name));
	score += 3*isFixed(&header->fixed_33, sizeof(header->fixed_33), 0x33);
	score += checkChksum(header->cchk, header->chk);
	return score;
}
Example #2
0
/*----------------------------------------------------------------------------------------------------------------------
|	Use samples in `fitting_sample' to parameterize a new BetaDistribution, which is then stored in `ref_dist'. 
|	Assumes `fitting_sample' has more than 1 element. 
*/
void MCMCUpdater::fitBetaWorkingPrior()
	{
	if (!isFixed())
		{
		PHYCAS_ASSERT(fitting_sample.size() > 1);
		double n = (double)fitting_sample.size();
		double sum = 0.0;
		double sum_of_squares = 0.0;
		for (double_vect_t::iterator i = fitting_sample.begin(); i != fitting_sample.end(); ++i)
			{
			double v = (*i);
			sum += v;
			sum_of_squares += v*v;
			}
		double mean = sum/n;
		double variance = (sum_of_squares - n*mean*mean)/(n - 1.0);

		// Let a, b be the parameters of a Beta(a,b) and let phi = a + b
		// Note that:
		//     mean = a/phi
		//   1-mean = b/phi
		// variance = a*b/[phi^2*(phi + 1)]
		// Letting z = mean*(1-mean)/variance,
		// phi can be estimated as z - 1
		// Now, a = mean*phi and b = (1-mean)*phi
		double phi = mean*(1.0-mean)/variance - 1.0;
		double a = phi*mean;
		double b = phi*(1.0 - mean);
		ref_dist = ProbDistShPtr(new BetaDistribution(a, b));
		// std::cerr << boost::str(boost::format("@@@@@@@@@ working prior is Beta(%g, %g) for updater %s: mean = %g, variance = %g") % a % b % getName() % mean % variance) << std::endl;
		}
	}
Example #3
0
SolverThread::SolverThread(QObject *parent)
    : BaseSolverThread(parent)
{
    m_mesh = new FEMTetrahedronMesh;
	
    bool hasData = 0;
#if TESTBLOCK
    m_mesh->generateBlocks(64,2,2, .5f, .5f, .5f);
    m_mesh->setDensity(30.f);
#else
	hasData = readMeshFromFile();
	if(!hasData)
		m_mesh->generateTest();
    m_mesh->setDensity(10.4f);
#endif
    
    unsigned totalPoints = m_mesh->numPoints();
	
	ConjugateGradientSolver::init(totalPoints);
    
    m_K_row = new MatrixMap[totalPoints];
	m_V = new Vector3F[totalPoints];
	m_F = new Vector3F[totalPoints]; 
	m_F0 = new Vector3F[totalPoints]; 
	
	int * fixed = isFixed();
	unsigned i;
	for(i=0; i < totalPoints; i++) m_V[i].setZero();
	
	if(hasData) {
		unsigned * anchor = (unsigned *)m_meshData.m_anchorBuf->data();
		for(i=0; i < totalPoints; i++) {
			fixed[i] = anchor[i];
		}
	}
	else {
		Vector3F * Xi = m_mesh->Xi();
		for(i=0; i < totalPoints; i++) {
			if(i==7 || i==5 || i==8 || i==18)
			//if(Xi[i].x<.1f)
				fixed[i]=1;
			else
				fixed[i]=0;   
		}
	}
	
	calculateK();
	clearStiffnessAssembly();
	m_mesh->recalcMassMatrix(fixed);
	initializePlastic();
	
	qDebug()<<"num points "<<m_mesh->numPoints();
	qDebug()<<"total mass "<<m_mesh->mass();
	qDebug()<<"num tetrahedrons "<<m_mesh->numTetrahedra();
	qDebug()<<"total volume "<<m_mesh->volume0();
	
	m_stiffnessMatrix = new CudaCSRMatrix;
	m_hostK = new BaseBuffer;
}
void ofxSimpleGuiContentSlider2d::onRelease() {
    bool isOnFixButton = x - this->x > width - fixboxWidth && y - this->y < fixboxWidth && bDrawFixButton;
    if (isOnFixButton) {
        toggleFix();
    } else if (!isFixed()) {
        lock = false;
    }
}
void ofxSimpleGuiButton::saveToXML(ofxXmlSettings &XML) {
    XML.addTag(controlType + "_" + key);
    XML.pushTag(controlType + "_" + key);
    XML.addValue("name", name);
    XML.addValue("value", getValue());
    XML.addValue("isFixed", isFixed());
    XML.popTag();
}
Example #6
0
boolean isSolved(unsigned short* sudoku)
{
	unsigned int i;
	for(i = 0; i < 256; i++)
		if(!isFixed(sudoku[i]))
			return false;
	return true;
}
Example #7
0
/*----------------------------------------------------------------------------------------------------------------------
|	Override of base class version adds the current GTR relative rate parameter value to the data already stored in 
|	`fitting_sample'.
*/
void GTRRateParam::educateWorkingPrior()
	{
	if (!isFixed())
		{
		PHYCAS_ASSERT(isPriorSteward());	// only prior stewards should be building working priors
		double rateparam = getCurrValueFromModel();
		fitting_sample.push_back(rateparam);
		}
	}
void ofxSimpleGuiContentSlider2d::saveToXML(ofxXmlSettings &XML) {
	XML.addTag(controlType + "_" + key);
	XML.pushTag(controlType + "_" + key);
	XML.addValue("name", name);
	XML.addValue("valueX", value->x);
	XML.addValue("valueY", value->y);
    XML.addValue("isFixed", isFixed());
	XML.popTag();
}
void ofxSimpleGuiButton::onRelease(int x, int y, int button) {
    bool isOnFixButton = x - this->x > width - fixboxWidth && y - this->y < fixboxWidth && bDrawFixButton;
    if (isOnFixButton) return;
    else if (!isFixed()) {
        isPressed = false;
        oldValue = *value = false;
        counter++;
    }
}
void ofxSimpleGuiContentSlider2d::onDragOver(int x, int y, int button) {
    if (!isFixed()) {
        if (bSecondPoint) {
            if (lock) point2.set(x - this->x, y - this->y - sliderTextHeight);
        } else {
            if (lock) point.set(x - this->x, y - this->y - sliderTextHeight);
        }
    }
	
}
void ofxSimpleGuiButton::draw(float x, float y) {
    setPos(x, y);

    glPushMatrix();
    glTranslatef(x, y, 0);

    ofEnableAlphaBlending();
    ofFill();
    setTextBGColor(!isFixed());
    ofRect(0, 0, width, height);

    setTextColor(!isFixed());
    ofCircle(height/3, height/2, height /5);
    ofDrawBitmapString(name + " (" + ofToString(counter)+")", height - 15, 26);
    ofDisableAlphaBlending();

    fixButtonDraw();

    glPopMatrix();
}
Example #12
0
void CMetab::refreshInitialConcentration()
{
  if (mpInitialExpression != NULL &&
      mpInitialExpression->getInfix() != "")
    mIConc = mpInitialExpression->calcValue();
  else
    mIConc =
      mIValue / mpCompartment->getInitialValue() * mpModel->getNumber2QuantityFactor();

  if (isFixed()) mConc = mIConc;
}
Example #13
0
void SolverThread::updatePosition(float dt) 
{
    unsigned totalPoints = m_mesh->numPoints();
    Vector3F * X = m_mesh->X();
    int * fixed = isFixed();
	for(unsigned k=0;k<totalPoints;k++) {
		if(fixed[k])
			continue;
		X[k] += m_V[k] * dt;
	}
}
Example #14
0
//-----------------------------------------------------------------
bool
Landslip::stoneModel(const Cube *model)
{
    bool change = false;
    if (!isStoned(model)) {
        if (isFixed(model) || isOnPad(model)) {
            stone(model);
            change = true;
        }
    }
    return change;
}
Example #15
0
//-----------------------------------------------------------------
bool
Landslip::isOnPad(const Cube *model) const
{
    const Cube::t_models pad = model->const_rules()->getResist(Dir::DIR_DOWN);
    Cube::t_models::const_iterator end = pad.end();
    for (Cube::t_models::const_iterator i = pad.begin(); i != end; ++i) {
        if (isFixed(*i)) {
            return true;
        }
    }
    return false;
}
Example #16
0
void SolverThread::computeForces() 
{
    int * fixed = isFixed();
	unsigned i=0; 
	unsigned totalPoints = m_mesh->numPoints();
	float * mass = m_mesh->M();
	for(i=0;i<totalPoints;i++) {
		m_F[i].setZero();
		if(fixed[i] < 1)
		//add gravity force only for non-fixed points
		    m_F[i] += gravity * mass[i];
	}
}
void ofxSimpleGuiButton::onPress(int x, int y, int button) {
    if (oldValue) {
        string s;
        ofLog(OF_LOG_ERROR, "gui/" + controlType + "/" + name + "に入れているvalueがfalseに戻されていません。");
    }
    bool isOnFixButton = x - this->x > width - fixboxWidth && y - this->y < fixboxWidth && bDrawFixButton;
    if (isOnFixButton) {
        toggleFix();
    } else if (!isFixed()) {
        isPressed = true;
        oldValue = (*value) = true;
    }
}
Example #18
0
/**
 * Let model to fall.
 * @return true when model is falling
 */
bool
Landslip::fallModel(Cube *model)
{
    bool falling = false;
    if (!isFixed(model)) {
        model->rules()->actionFall();
        falling = true;
    }
    else {
        bool lastFall = model->rules()->clearLastFall();
        if (lastFall && m_impact < model->getWeight()) {
            m_impact = model->getWeight();
        }
    }
    return falling;
}
void ofxSimpleGuiContentSlider2d::onPress(int x, int y, int button) {
    bool isOnFixButton = x - this->x > width - fixboxWidth && y - this->y < fixboxWidth && bDrawFixButton;
    bool isOnSecondButton = x - this->x > secBtnPos.x && x-this->x < secBtnPos.x + secondPointBoxWidth && y - this->y < secondPointBoxWidth;
    bool isOnSlider = (y - this->y) > sliderTextHeight;
    if (isOnSecondButton) {
        bSecondPoint = !bSecondPoint;
    }
    if (isOnFixButton) {
        toggleFix();
    } else if (!isFixed() && isOnSlider) {
        lock = true;
        if (bSecondPoint) {
            point2.set(x - this->x, y - this->y - sliderTextHeight);
        } else {
            point.set(x - this->x, y - this->y - sliderTextHeight);
        }
    }
}
Example #20
0
boolean solvedCellSimplifiesUnit(unsigned short* sudoku, int recursionLevel)
{
	boolean success = false;

	unsigned int row, col;
	for(row = 0; row < 16; row++)
		for(col = 0; col < 16; col++)
		{
			unsigned short candidates = sudoku[16 * row + col];
			if(candidates == 0)
			{
				guessConflict[recursionLevel] = true;
				return;
			}
			if(!isFixed(candidates))
				continue;

			unsigned int i;
			for(i = 1; i < 16; i++)
			{
				// remove from row
				unsigned int cell = indexOfOtherRowCells(row, col, i);
				success |= sudoku[cell] & candidates;
				sudoku[cell] &= ~candidates;
				
				// remove from col
				cell = indexOfOtherColCells(row, col, i);
				success |= sudoku[cell] & candidates;
				sudoku[cell] &= ~candidates;
				
				// remove from box
				cell = indexOfOtherBoxCells(row, col, i);
				success |= sudoku[cell] & candidates;
				sudoku[cell] &= ~candidates;
			}
		}
	if(success && recursionLevel < 0)
	{
		printf("SolvedCellSimplifiedUnit\n");
		printSudoku(sudoku);
	}
	return success;
}
Example #21
0
/*----------------------------------------------------------------------------------------------------------------------
|	Use samples in `fitting_sample' to parameterize a new LognormalDistribution, which is then stored in `ref_dist'. 
|	Assumes `fitting_sample' has more than 1 element. 
*/
void MCMCUpdater::fitLognormalWorkingPrior()
	{
	if (!isFixed())
		{
		PHYCAS_ASSERT(fitting_sample.size() > 1);
		double n = (double)fitting_sample.size();
		double sum = 0.0;
		double sum_of_squares = 0.0;
		for (double_vect_t::iterator i = fitting_sample.begin(); i != fitting_sample.end(); ++i)
			{
			double v = (*i);
			double logv = log(v);
			sum += logv;
			sum_of_squares += logv*logv;
			}
		double logmean = sum/n;	
		double logvar = (sum_of_squares - n*logmean*logmean)/(n - 1.0);
		double logsd = sqrt(logvar);
		ref_dist = ProbDistShPtr(new LognormalDistribution(logmean, logsd));
		}
	}
Example #22
0
/* initLayout:
 * Initialize node coordinates. If the node already has
 * a position, use it.
 * Return true if some node is fixed.
 */
int
initLayout(vtx_data * graph, int n, int dim, double **coords,
	   node_t ** nodes)
{
    node_t *np;
    double *xp;
    double *yp;
    double *pt;
    int i, d;
    int pinned = 0;

    xp = coords[0];
    yp = coords[1];
    for (i = 0; i < n; i++) {
	np = nodes[i];
	if (hasPos(np)) {
	    pt = ND_pos(np);
	    *xp++ = *pt++;
	    *yp++ = *pt++;
	    if (dim > 2) {
		for (d = 2; d < dim; d++)
		    coords[d][i] = *pt++;
	    }
	    if (isFixed(np))
		pinned = 1;
	} else {
	    *xp++ = drand48();
	    *yp++ = drand48();
	    if (dim > 2) {
		for (d = 2; d < dim; d++)
		    coords[d][i] = drand48();
	    }
	}
    }

    for (d = 0; d < dim; d++)
	orthog1(n, coords[d]);

    return pinned;
}
Example #23
0
/*----------------------------------------------------------------------------------------------------------------------
|	Retrieves current value for the parameter being managed by this updater, then returns log of the working prior 
|	probability density at that value. If this updater is not a prior steward, simply returns 0.0.
*/
double MCMCUpdater::recalcWorkingPrior() const
	{
	if (isFixed() || !isPriorSteward())
		return 0.0;
		
	//std::cerr << boost::str(boost::format("calling MCMCUpdater::recalcWorkingPrior for %s") % getName()) << std::endl;//temp
	double lnwp = 0.0;
	if (ref_dist)
		{
		double value = getCurrValueFromModel();
		try 
			{
			lnwp = ref_dist->GetLnPDF(value);
			}
		catch(XProbDist &)
			{
			PHYCAS_ASSERT(0);
			}
		//std::cerr << boost::str(boost::format("%.8f <-- %.8f <-- %s <-- %s") % lnwp % value % ref_dist->GetDistributionDescription() % getName()) << std::endl;//temp
		}
	else
		{
		double_vect_t values;
		getCurrValuesFromModel(values);	
		try 
			{
			PHYCAS_ASSERT(mv_ref_dist);
			lnwp = mv_ref_dist->GetLnPDF(values);
			}
		catch(XProbDist &)
			{
			PHYCAS_ASSERT(0);
			}
		//std::cerr << boost::str(boost::format("%.8f <-- {") % lnwp);//temp
		//std::copy(values.begin(), values.end(), std::ostream_iterator<double>(std::cerr, " "));//temp
		//std::cerr << boost::str(boost::format("} <-- %s <-- %s") % mv_ref_dist->GetDistributionDescription() % getName()) << std::endl;//temp
		}
	return lnwp;
	}
Example #24
0
/*----------------------------------------------------------------------------------------------------------------------
|	Use samples in `fitting_sample' to parameterize a new GammaDistribution, which is then stored in `ref_dist'. 
|	Assumes `fitting_sample' has more than 1 element. 
*/
void MCMCUpdater::fitGammaWorkingPrior()
	{
	if (!isFixed())
		{
		PHYCAS_ASSERT(fitting_sample.size() > 1);
		double n = (double)fitting_sample.size();
		double sum = 0.0;
		double sum_of_squares = 0.0;
		for (double_vect_t::iterator i = fitting_sample.begin(); i != fitting_sample.end(); ++i)
			{
			double v = (*i);
			sum += v;
			sum_of_squares += v*v;
			}
		double mean = sum/n;	// shape*scale
		double variance = (sum_of_squares - n*mean*mean)/(n - 1.0);	// shape*scale^2
		double scale = variance/mean;
		PHYCAS_ASSERT(scale > 0.0);
		double shape = mean/scale;
		// std::cerr << boost::str(boost::format("@@@@@@@@@ working prior is Gamma(%g,%g) for updater %s: mean = %g, variance = %g") % shape % scale % getName() % mean % variance) << std::endl;
		ref_dist = ProbDistShPtr(new GammaDistribution(shape, scale));
		}
	}
Example #25
0
static EVisibility elementImplicitVisibility(const Element& element)
{
    auto* renderer = element.renderer();
    if (!renderer)
        return VISIBLE;

    auto& style = renderer->style();

    auto width = style.width();
    auto height = style.height();
    if ((width.isFixed() && width.value() <= 0) || (height.isFixed() && height.value() <= 0))
        return HIDDEN;

    auto top = style.top();
    auto left = style.left();
    if (left.isFixed() && width.isFixed() && -left.value() >= width.value())
        return HIDDEN;

    if (top.isFixed() && height.isFixed() && -top.value() >= height.value())
        return HIDDEN;
    return VISIBLE;
}
Example #26
0
// 中間ポートを利用する場合のルーティング(中間からシンクまで)
bool routingIToSink(int trgt_line_id){

	Line* trgt_line = board->line(trgt_line_id);
	
	vector<vector<IntraBox*> > my_board(board->getSizeY(), vector<IntraBox*>(board->getSizeX()));
	IntraBox init = {
		INT_MAX,INT_MAX,INT_MAX,INT_MAX,
		{false,false,false,false},
		{false,false,false,false},
		{false,false,false,false},
		{false,false,false,false}};
	
	for(int y=0;y<board->getSizeY();y++){
		for(int x=0;x<board->getSizeX();x++){
			my_board[y][x] = new IntraBox;
			*(my_board[y][x]) = init;
		}
	}
	
	// 通れないマスを規定
	vector<Point>* trgt_track = trgt_line->getTrack();
	map<int,map<int,bool> > can_pass;
	for(int y=-1;y<=board->getSizeY();y++){
		for(int x=-1;x<=board->getSizeX();x++){
			can_pass[y][x] = true;
		}
	}
	for(int i=0;i<(int)(trgt_track->size());i++){
		int tmp_x = (*trgt_track)[i].x;
		int tmp_y = (*trgt_track)[i].y;
		can_pass[tmp_y][tmp_x] = false;
		can_pass[tmp_y][tmp_x-1] = false;
		can_pass[tmp_y][tmp_x+1] = false;
		can_pass[tmp_y-1][tmp_x] = false;
		can_pass[tmp_y+1][tmp_x] = false;
	}
	
	// ソースから中間までの経路を一時保存
	vector<Point> before_track;
	for(int i=0;i<(int)(trgt_track->size());i++){
		before_track.push_back((*trgt_track)[i]);
	}
	trgt_track->clear();
	
	
	int start_x = trgt_line->getInterX();
	int start_y = trgt_line->getInterY();
	
	IntraBox* start = my_board[start_y][start_x];
	start->ne = 0; start->nw = 0;
	start->se = 0; start->sw = 0;
	
	queue<Search> qu;
	// 北方向
	if(can_pass[start_y-1][start_x] && isInserted(start_x,start_y-1,SOUTH) && isFixed(start_x,start_y,NORTH,-1,trgt_line_id)){
		Search trgt = {start_x,start_y-1,SOUTH,-1};
		qu.push(trgt);
	}
	// 東方向
	if(can_pass[start_y][start_x+1] && isInserted(start_x+1,start_y,WEST) && isFixed(start_x,start_y,EAST,-1,trgt_line_id)){
		Search trgt = {start_x+1,start_y,WEST,-1};
		qu.push(trgt);
	}
	// 南方向
	if(can_pass[start_y+1][start_x] && isInserted(start_x,start_y+1,NORTH) && isFixed(start_x,start_y,SOUTH,-1,trgt_line_id)){
		Search trgt = {start_x,start_y+1,NORTH,-1};
		qu.push(trgt);
	}
	// 西方向
	if(can_pass[start_y][start_x-1] && isInserted(start_x-1,start_y,EAST) && isFixed(start_x,start_y,WEST,-1,trgt_line_id)){
		Search trgt = {start_x-1,start_y,EAST,-1};
		qu.push(trgt);
	}
	
	while(!qu.empty()){
		
		Search trgt = qu.front();
		qu.pop();
		
		//cout << "(" << trgt.x << "," << trgt.y << ")" << endl;
		
		Box* trgt_box = board->box(trgt.x,trgt.y);
		IntraBox* trgt_ibox = my_board[trgt.y][trgt.x];
		bool update = false;
		
		int turn_count = 0;
		if(trgt.c != trgt.d) turn_count++;
	
		// コスト計算
		if(trgt.d == SOUTH){ // 南から来た
			IntraBox* find_ibox = my_board[trgt.y+1][trgt.x];
			// タッチ数
			int touch_count = countLineNum(trgt.x,trgt.y) - trgt_box->getSouthNum();
			if(touch_count < 0){ cout << "error! (error: 24)" << endl; exit(24); }
			// コスト
			int cost_se = (find_ibox->ne) + ML + touch_count * penalty_T + turn_count * BT;
			int cost_ne = (find_ibox->ne) + ML + touch_count * penalty_T + trgt_box->getEastNum() * penalty_C + turn_count * BT;
			int cost_sw = (find_ibox->nw) + ML + touch_count * penalty_T + turn_count * BT;
			int cost_nw = (find_ibox->nw) + ML + touch_count * penalty_T + trgt_box->getWestNum() * penalty_C + turn_count * BT;
			// 南東マス
			if(cost_se < trgt_ibox->se){
				update = true;
				trgt_ibox->se = cost_se;
				(trgt_ibox->d_se).n = false;
				(trgt_ibox->d_se).e = false;
				(trgt_ibox->d_se).s = true;
				(trgt_ibox->d_se).w = false;
			}
			else if(cost_se == trgt_ibox->se){
				(trgt_ibox->d_se).s = true;
			}
			// 北東マス
			if(cost_ne < trgt_ibox->ne){
				update = true;
				trgt_ibox->ne = cost_ne;
				(trgt_ibox->d_ne).n = false;
				(trgt_ibox->d_ne).e = false;
				(trgt_ibox->d_ne).s = true;
				(trgt_ibox->d_ne).w = false;
			}
			else if(cost_ne == trgt_ibox->ne){
				(trgt_ibox->d_ne).s = true;
			}
			// 南西マス
			if(cost_sw < trgt_ibox->sw){
				update = true;
				trgt_ibox->sw = cost_sw;
				(trgt_ibox->d_sw).n = false;
				(trgt_ibox->d_sw).e = false;
				(trgt_ibox->d_sw).s = true;
				(trgt_ibox->d_sw).w = false;
			}
			else if(cost_sw == trgt_ibox->sw){
				(trgt_ibox->d_sw).s = true;
			}
			// 北西マス
			if(cost_nw < trgt_ibox->nw){
				update = true;
				trgt_ibox->nw = cost_nw;
				(trgt_ibox->d_nw).n = false;
				(trgt_ibox->d_nw).e = false;
				(trgt_ibox->d_nw).s = true;
				(trgt_ibox->d_nw).w = false;
			}
			else if(cost_nw == trgt_ibox->nw){
				(trgt_ibox->d_nw).s = true;
			}
		}
		if(trgt.d == WEST){ // 西から来た
			IntraBox* find_ibox = my_board[trgt.y][trgt.x-1];
			// タッチ数
			int touch_count = countLineNum(trgt.x,trgt.y) - trgt_box->getWestNum();
			if(touch_count < 0){ cout << "error! (error: 25)" << endl; exit(25); }
			// コスト
			int cost_nw = (find_ibox->ne) + ML + touch_count * penalty_T + turn_count * BT;
			int cost_ne = (find_ibox->ne) + ML + touch_count * penalty_T + trgt_box->getNorthNum() * penalty_C + turn_count * BT;
			int cost_sw = (find_ibox->se) + ML + touch_count * penalty_T + turn_count * BT;
			int cost_se = (find_ibox->se) + ML + touch_count * penalty_T + trgt_box->getSouthNum() * penalty_C + turn_count * BT;
			// 北西マス
			if(cost_nw < trgt_ibox->nw){
				update = true;
				trgt_ibox->nw = cost_nw;
				(trgt_ibox->d_nw).n = false;
				(trgt_ibox->d_nw).e = false;
				(trgt_ibox->d_nw).s = false;
				(trgt_ibox->d_nw).w = true;
			}
			else if(cost_nw == trgt_ibox->nw){
				(trgt_ibox->d_nw).w = true;
			}
			// 北東マス
			if(cost_ne < trgt_ibox->ne){
				update = true;
				trgt_ibox->ne = cost_ne;
				(trgt_ibox->d_ne).n = false;
				(trgt_ibox->d_ne).e = false;
				(trgt_ibox->d_ne).s = false;
				(trgt_ibox->d_ne).w = true;
			}
			else if(cost_ne == trgt_ibox->ne){
				(trgt_ibox->d_ne).w = true;
			}
			// 南西マス
			if(cost_sw < trgt_ibox->sw){
				update = true;
				trgt_ibox->sw = cost_sw;
				(trgt_ibox->d_sw).n = false;
				(trgt_ibox->d_sw).e = false;
				(trgt_ibox->d_sw).s = false;
				(trgt_ibox->d_sw).w = true;
			}
			else if(cost_sw == trgt_ibox->sw){
				(trgt_ibox->d_sw).w = true;
			}
			// 南東マス
			if(cost_se < trgt_ibox->se){
				update = true;
				trgt_ibox->se = cost_se;
				(trgt_ibox->d_se).n = false;
				(trgt_ibox->d_se).e = false;
				(trgt_ibox->d_se).s = false;
				(trgt_ibox->d_se).w = true;
			}
			else if(cost_se == trgt_ibox->se){
				(trgt_ibox->d_se).w = true;
			}
		}
		if(trgt.d == NORTH){ // 北から来た
			IntraBox* find_ibox = my_board[trgt.y-1][trgt.x];
			// タッチ数
			int touch_count = countLineNum(trgt.x,trgt.y) - trgt_box->getNorthNum();
			if(touch_count < 0){ cout << "error! (error: 26)" << endl; exit(26); }
			// コスト
			int cost_ne = (find_ibox->se) + ML + touch_count * penalty_T + turn_count * BT;
			int cost_se = (find_ibox->se) + ML + touch_count * penalty_T + trgt_box->getEastNum() * penalty_C + turn_count * BT;
			int cost_nw = (find_ibox->sw) + ML + touch_count * penalty_T + turn_count * BT;
			int cost_sw = (find_ibox->sw) + ML + touch_count * penalty_T + trgt_box->getWestNum() * penalty_C + turn_count * BT;
			// 北東マス
			if(cost_ne < trgt_ibox->ne){
				update = true;
				trgt_ibox->ne = cost_ne;
				(trgt_ibox->d_ne).n = true;
				(trgt_ibox->d_ne).e = false;
				(trgt_ibox->d_ne).s = false;
				(trgt_ibox->d_ne).w = false;
			}
			else if(cost_ne == trgt_ibox->ne){
				(trgt_ibox->d_ne).n = true;
			}
			// 南東マス
			if(cost_se < trgt_ibox->se){
				update = true;
				trgt_ibox->se = cost_se;
				(trgt_ibox->d_se).n = true;
				(trgt_ibox->d_se).e = false;
				(trgt_ibox->d_se).s = false;
				(trgt_ibox->d_se).w = false;
			}
			else if(cost_se == trgt_ibox->se){
				(trgt_ibox->d_se).n = true;
			}
			// 北西マス
			if(cost_nw < trgt_ibox->nw){
				update = true;
				trgt_ibox->nw = cost_nw;
				(trgt_ibox->d_nw).n = true;
				(trgt_ibox->d_nw).e = false;
				(trgt_ibox->d_nw).s = false;
				(trgt_ibox->d_nw).w = false;
			}
			else if(cost_nw == trgt_ibox->nw){
				(trgt_ibox->d_nw).n = true;
			}
			// 南西マス
			if(cost_sw < trgt_ibox->sw){
				update = true;
				trgt_ibox->sw = cost_sw;
				(trgt_ibox->d_sw).n = true;
				(trgt_ibox->d_sw).e = false;
				(trgt_ibox->d_sw).s = false;
				(trgt_ibox->d_sw).w = false;
			}
			else if(cost_sw == trgt_ibox->sw){
				(trgt_ibox->d_sw).n = true;
			}
		}
		if(trgt.d == EAST){ // 東から来た
			IntraBox* find_ibox = my_board[trgt.y][trgt.x+1];
			// タッチ数
			int touch_count = countLineNum(trgt.x,trgt.y) - trgt_box->getEastNum();
			if(touch_count < 0){ cout << "error! (error: 27)" << endl; exit(27); }
			// コスト
			int cost_ne = (find_ibox->nw) + ML + touch_count * penalty_T + turn_count * BT;
			int cost_nw = (find_ibox->nw) + ML + touch_count * penalty_T + trgt_box->getNorthNum() * penalty_C + turn_count * BT;
			int cost_se = (find_ibox->sw) + ML + touch_count * penalty_T + turn_count * BT;
			int cost_sw = (find_ibox->sw) + ML + touch_count * penalty_T + trgt_box->getSouthNum() * penalty_C + turn_count * BT;
			// 北東マス
			if(cost_ne < trgt_ibox->ne){
				update = true;
				trgt_ibox->ne = cost_ne;
				(trgt_ibox->d_ne).n = false;
				(trgt_ibox->d_ne).e = true;
				(trgt_ibox->d_ne).s = false;
				(trgt_ibox->d_ne).w = false;
			}
			else if(cost_ne == trgt_ibox->ne){
				(trgt_ibox->d_ne).e = true;
			}
			// 北西マス
			if(cost_nw < trgt_ibox->nw){
				update = true;
				trgt_ibox->nw = cost_nw;
				(trgt_ibox->d_nw).n = false;
				(trgt_ibox->d_nw).e = true;
				(trgt_ibox->d_nw).s = false;
				(trgt_ibox->d_nw).w = false;
			}
			else if(cost_nw == trgt_ibox->nw){
				(trgt_ibox->d_nw).e = true;
			}
			// 南東マス
			if(cost_se < trgt_ibox->se){
				update = true;
				trgt_ibox->se = cost_se;
				(trgt_ibox->d_se).n = false;
				(trgt_ibox->d_se).e = true;
				(trgt_ibox->d_se).s = false;
				(trgt_ibox->d_se).w = false;
			}
			else if(cost_se == trgt_ibox->se){
				(trgt_ibox->d_se).e = true;
			}
			// 南西マス
			if(cost_sw < trgt_ibox->sw){
				update = true;
				trgt_ibox->sw = cost_sw;
				(trgt_ibox->d_sw).n = false;
				(trgt_ibox->d_sw).e = true;
				(trgt_ibox->d_sw).s = false;
				(trgt_ibox->d_sw).w = false;
			}
			else if(cost_sw == trgt_ibox->sw){
				(trgt_ibox->d_sw).e = true;
			}
		}
		
		if(!update) continue;
		
		// 北方向
		if(trgt.d!=NORTH && can_pass[trgt.y-1][trgt.x] && isInserted(trgt.x,trgt.y-1,SOUTH) && isFixed(trgt.x,trgt.y,NORTH,trgt.d,trgt_line_id)){
			Search next = {trgt.x,trgt.y-1,SOUTH,trgt.d};
			qu.push(next);
		}
		// 東方向
		if(trgt.d!=EAST && can_pass[trgt.y][trgt.x+1] && isInserted(trgt.x+1,trgt.y,WEST) && isFixed(trgt.x,trgt.y,EAST,trgt.d,trgt_line_id)){
			Search next = {trgt.x+1,trgt.y,WEST,trgt.d};
			qu.push(next);
		}
		// 南方向
		if(trgt.d!=SOUTH && can_pass[trgt.y+1][trgt.x] && isInserted(trgt.x,trgt.y+1,NORTH) && isFixed(trgt.x,trgt.y,SOUTH,trgt.d,trgt_line_id)){
			Search next = {trgt.x,trgt.y+1,NORTH,trgt.d};
			qu.push(next);
		}
		// 西方向
		if(trgt.d!=WEST && can_pass[trgt.y][trgt.x-1] && isInserted(trgt.x-1,trgt.y,EAST) && isFixed(trgt.x,trgt.y,WEST,trgt.d,trgt_line_id)){
			Search next = {trgt.x-1,trgt.y,EAST,trgt.d};
			qu.push(next);
		}
		
	}
	
	// cout << endl;
	// for(int y=0;y<board->getSizeY();y++){
		// for(int x=0;x<board->getSizeX();x++){
			// IntraBox* trgt_box = my_board[y][x];
			// if(trgt_box->nw > 10000){
				// cout << " +";
			// }
			// else{
				// cout << setw(2) << trgt_box->nw;
			// }
			// if(trgt_box->ne > 10000){
				// cout << " +";
			// }
			// else{
				// cout << setw(2) << trgt_box->ne;
			// }
			// cout << " ";
		// }
		// cout << endl;
		// for(int x=0;x<board->getSizeX();x++){
			// IntraBox* trgt_box = my_board[y][x];
			// if(trgt_box->sw > 10000){
				// cout << " +";
			// }
			// else{
				// cout << setw(2) << trgt_box->sw;
			// }
			// if(trgt_box->se > 10000){
				// cout << " +";
			// }
			// else{
				// cout << setw(2) << trgt_box->se;
			// }
			// cout << " ";
		// }
		// cout << endl;
	// }
	
	
	// バックトレース
	int now_x = trgt_line->getSinkX();
	int now_y = trgt_line->getSinkY();
	int intra_box = -1;
	
	vector<int> adj_cost(8);
	if(now_y!=0){
		adj_cost[0] = my_board[now_y-1][now_x]->sw; // 北,南西
		adj_cost[1] = my_board[now_y-1][now_x]->se; // 北,南東
	}
	else{
		adj_cost[0] = INT_MAX;
		adj_cost[1] = INT_MAX;
	}
	if(now_x!=(board->getSizeX()-1)){
		adj_cost[2] = my_board[now_y][now_x+1]->nw; // 東,北西
		adj_cost[3] = my_board[now_y][now_x+1]->sw; // 東,南西
	}
	else{
		adj_cost[2] = INT_MAX;
		adj_cost[3] = INT_MAX;
	}
	if(now_y!=(board->getSizeY()-1)){
		adj_cost[4] = my_board[now_y+1][now_x]->ne; // 南,北東
		adj_cost[5] = my_board[now_y+1][now_x]->nw; // 南,北西
	}
	else{
		adj_cost[4] = INT_MAX;
		adj_cost[5] = INT_MAX;
	}
	if(now_x!=0){
		adj_cost[6] = my_board[now_y][now_x-1]->se; // 西,南東
		adj_cost[7] = my_board[now_y][now_x-1]->ne; // 西,北東
	}
	else{
		adj_cost[6] = INT_MAX;
		adj_cost[7] = INT_MAX;
	}
	vector<int> min_direction_array;
	int min_cost = INT_MAX, threshold_cost = 10000, min_direction_array_size;
	for (int trying = 0; trying < 5; trying++) {
		for (int a = 0; a < 8; a++) {
			if (adj_cost[a] > threshold_cost) {
				continue;
			}
			if (adj_cost[a] < min_cost) {
				min_direction_array.clear();
				min_direction_array.push_back(a);
				min_cost = adj_cost[a];
			} else if(adj_cost[a] == min_cost){
				min_direction_array.push_back(a);
			}
		}
		min_direction_array_size = (int)(min_direction_array.size());
		if (min_direction_array_size != 0) {
			break;
		}
		threshold_cost *= 10;
	}
	if (min_direction_array_size == 0) {
		for (int i = 0; i < (int)(before_track.size()); i++) {
			trgt_track->push_back(before_track[i]);
		}
		return false;
	}
	int adj_count = (int)mt_genrand_int32(0, min_direction_array_size - 1);
	int adj_id = min_direction_array[adj_count];
	//cout << min_cost << endl;
	
	
	//bool p_n = false;
	//bool p_e = false;
	//bool p_s = false;
	//bool p_w = false;
	switch(adj_id){
		case 0: // 北,南西
		now_y = now_y - 1; intra_box = SW;
		//p_n = true;
		break;
		case 1: // 北,南東
		now_y = now_y - 1; intra_box = SE;
		//p_n = true;
		break;
		case 2: // 東,北西
		now_x = now_x + 1; intra_box = NW;
		//p_e = true;
		break;
		case 3: // 東,南西
		now_x = now_x + 1; intra_box = SW;
		//p_e = true;
		break;
		case 4: // 南,北東
		now_y = now_y + 1; intra_box = NE;
		//p_s = true;
		break;
		case 5: // 南,北西
		now_y = now_y + 1; intra_box = NW;
		//p_s = true;
		break;
		case 6: // 西,南東
		now_x = now_x - 1; intra_box = SE;
		//p_w = true;
		break;
		case 7: // 西,北東
		now_x = now_x - 1; intra_box = NE;
		//p_w = true;
		break;
	}
	
	while(now_x!=start_x || now_y!=start_y){
		
		//cout << now_x << "," << now_y << endl;
		Point p = {now_x, now_y};
		trgt_line->pushPointToTrack(p);
		
		Direction trgt_d;
		switch(intra_box){
			case NE:
			trgt_d = my_board[now_y][now_x]->d_ne;
			break;
			case NW:
			trgt_d = my_board[now_y][now_x]->d_nw;
			break;
			case SE:
			trgt_d = my_board[now_y][now_x]->d_se;
			break;
			case SW:
			trgt_d = my_board[now_y][now_x]->d_sw;
			break;
			default:
			assert(!"Undefined Intra-Box");
			break;
		}
		
		vector<int> next_direction_array;
		if(trgt_d.n) next_direction_array.push_back(NORTH);
		if(trgt_d.e) next_direction_array.push_back(EAST);
		if(trgt_d.s) next_direction_array.push_back(SOUTH);
		if(trgt_d.w) next_direction_array.push_back(WEST);
		//cout << (int)(next_direction_array.size()) << endl;
		
		int next_count = (int)mt_genrand_int32(0, (int)(next_direction_array.size()) - 1);
		int next_id = next_direction_array[next_count];
		
		switch(next_id){
			case NORTH:
			now_y = now_y - 1; // 北へ
			if(intra_box == NE || intra_box == SE) intra_box = SE;
			if(intra_box == NW || intra_box == SW) intra_box = SW;
			//p_n = true; p_e = false; p_s = false; p_w = false;
			break;
			case EAST:
			now_x = now_x + 1; // 東へ
			if(intra_box == NE || intra_box == NW) intra_box = NW;
			if(intra_box == SE || intra_box == SW) intra_box = SW;
			//p_n = false; p_e = true; p_s = false; p_w = false;
			break;
			case SOUTH:
			now_y = now_y + 1; // 南へ
			if(intra_box == NE || intra_box == SE) intra_box = NE;
			if(intra_box == NW || intra_box == SW) intra_box = NW;
			//p_n = false; p_e = false; p_s = true; p_w = false;
			break;
			case WEST:
			now_x = now_x - 1; // 西へ
			if(intra_box == NE || intra_box == NW) intra_box = NE;
			if(intra_box == SE || intra_box == SW) intra_box = SE;
			//p_n = false; p_e = false; p_s = false; p_w = true;
			break;
		}
	}

	// ターゲットラインのトラックを整理する
	bool retry = true;
	while (retry) {
		retry = false;

		// トラックを一時退避 (コピー) する
		vector<Point> tmp_track;
		for (int i = 0; i < (int)(trgt_track->size()); i++) {
			tmp_track.push_back((*trgt_track)[i]);
		}

		// 冗長部分を排除してトラックを整理
		trgt_track->clear();
		for (int i = 0; i < (int)(tmp_track.size()); i++) {
			if ((int)(tmp_track.size()) - 2 <= i) {
				trgt_track->push_back(tmp_track[i]);
				continue;
			}
			if (tmp_track[i].x == tmp_track[i + 2].x && tmp_track[i].y == tmp_track[i + 2].y) {
				retry = true;
				i++;
				continue;
			}
			trgt_track->push_back(tmp_track[i]);
		}
	}
	
	// 中間ポートと中間からソースまでの経路を追加
	Point trgt_point = {trgt_line->getInterX(), trgt_line->getInterY()};
	trgt_track->push_back(trgt_point);
	for(int i=0;i<(int)(before_track.size());i++){
		trgt_track->push_back(before_track[i]);
	}
	
	// 表示
	// map<int,map<int,int> > for_print;
	// for(int y=0;y<board->getSizeY();y++){
		// for(int x=0;x<board->getSizeX();x++){
			// Box* trgt_box = board->box(x,y);
			// if(trgt_box->isTypeBlank()){
				// for_print[y][x] = -1;
			// }
			// else{
				// for_print[y][x] = trgt_box->getNumber();
			// }
		// }
	// }
	// for(int i=0;i<(int)(trgt_track->size());i++){
		// int point = (*trgt_track)[i];
		// int point_x = point % board->getSizeX();
		// int point_y = point / board->getSizeX();
		// for_print[point_y][point_x] = -2;
	// }
	// for(int y=0;y<board->getSizeY();y++){
		// for(int x=0;x<board->getSizeX();x++){
			// if(for_print[y][x] == -2) cout << "@";
			// else if(for_print[y][x] == -1) cout << "+";
			// else{
				// if(for_print[y][x] < 10){
					// cout << for_print[y][x];
				// }
				// else{
					// cout << changeIntToChar(for_print[y][x]);
				// }
			// }
		// }
		// cout << endl;
	// }
	
	for(int y=0;y<board->getSizeY();y++){
		for(int x=0;x<board->getSizeX();x++){
			delete my_board[y][x];
		}
	}
	
	return true;
}
Example #27
0
/** This method doesn't create a tie
 * @param i :: A declared parameter index to be fixed
 */
void ChFun::fix(size_t i)
{
  if ( isFixed(i) ) return;
  m_isFixed[i] = true;
}
Example #28
0
boolean findSingles(unsigned short* sudoku, int recursionLevel)
{
	boolean success = false;

	unsigned int row, col;
	for(row = 0; row < 16; row++)
		for(col = 0; col < 16; col++)
		{
			if(isFixed(sudoku[16 * row + col]))
				continue;

			/**
			Collect all other cells from the current unit via OR, then invert the mask and AND it with the cell candidates
			**/
			unsigned int i;
			unsigned short mask = 0x0000;
			for(i = 1; i < 16; i++)
			{
				unsigned int cell = indexOfOtherRowCells(row, col, i);
				mask |= sudoku[cell];
			}
			if(sudoku[16 * row + col] & ~mask)
			{
				success = true;
				sudoku[16 * row + col] &= ~mask;
				continue;
			}

			mask = 0x0000;
			for(i = 1; i < 16; i++)
			{
				unsigned int cell = indexOfOtherColCells(row, col, i);
				mask |= sudoku[cell];
			}
			if(sudoku[16 * row + col] & ~mask)
			{
				success = true;
				sudoku[16 * row + col] &= ~mask;
				continue;
			}

			mask = 0x0000;
			for(i = 1; i < 16; i++)
			{
				unsigned int cell = indexOfOtherBoxCells(row, col, i);
				mask |= sudoku[cell];
			}
			if(sudoku[16 * row + col] & ~mask)
			{
				success = true;
				sudoku[16 * row + col] &= ~mask;
				continue;
			}
		}
	if(success && recursionLevel < 0)
	{
		printf("findSingles\n");
		printSudoku(sudoku);
	}
	return success;
}
Example #29
0
/** Makes a parameter active again. It doesn't change the parameter's tie.
 * @param i :: A declared parameter index to be restored to active
 */
void ChFun::unfix(size_t i)
{
  if ( !isFixed(i) ) return;
  m_isFixed[i] = false;
}
void ofxSimpleGuiContentSlider2d::draw(float x, float y) {
	setPos(x, y);
	ofEnableAlphaBlending();
	glPushMatrix();
	glTranslatef(x, y, 0);
    
    ofFill();
    glColor4f(0, 0, 0, 1.0f);
	ofRect(0, sliderTextHeight, width, sliderHeight);
	
	ofSetColor(255, 255, 255, 255);
	content->draw(0, sliderTextHeight, fixwidth, fixheight);
    
    setTextBGColor(!isFixed());
    ofRect(0, 0, width, sliderTextHeight);
    
    setTextColor(!isFixed());
    char vs[64];
    std::sprintf(vs, "\nx:%.2f\ny:%.2f", value->x,value->y);
    ofDrawBitmapString(name + vs , 6, 15);
    setTextColor2(!isFixed());
    char vs2[64];
    std::sprintf(vs2, "\n\nx:%.2f\ny:%.2f", value2->x,value2->y);
    ofDrawBitmapString(vs2 , secBtnPos.x, 0);
    ofSetHexColor(0xffffff);
    //////////
//    ofSetColor(0, 0, 0,0);
//    setContent2DSliderBGColor(!isFixed());
//    if (!isFixed()) ofRect(0, sliderTextHeight, fixwidth, fixheight);
    ofTranslate((int)0.0f, (int)sliderTextHeight);
    if (!isFixed()) {
        ofSetHexColor(0xFFFFFF);
        ofCircle(point.x, point.y, 2);
        ofLine(point.x, 0, point.x, fixheight);
        ofLine(0, point.y,width, point.y);
        if (bSecondPoint) {
            ofSetHexColor(0xFFFF00);
            ofCircle(point2.x, point2.y, 2);
            ofLine(point2.x, 0, point2.x, fixheight);
            ofLine(0, point2.y,width, point2.y);
        }
        ofSetHexColor(0xFFFFFF);
        ofRectangle maxxB = base64GetStringBoundingBox("X:" + ofToString(max.x));
        char valueString[64];
        std::sprintf(valueString,"( %.2f , %.2f )",(*value).x, (*value).y);
        ofRectangle valueStringBox = base64GetStringBoundingBox(valueString);
        base64DrawBitmapString("(" + ofToString(min.x) + "," + ofToString(min.y) + ")", 1, 2);
        base64DrawBitmapString("X:" + ofToString(max.x), width - maxxB.width - 1, 2);
        base64DrawBitmapString("Y:" + ofToString(max.y), 1, fixheight - maxxB.height -1);
        if (width/2 > point.x && fixheight/2 > (point.y - y)){ //左上にあるとき
            base64DrawBitmapString(valueString, point.x + 3, point.y + 3);
        } else if (width/2 < point.x && fixheight/2 > (point.y)) {//右上
            base64DrawBitmapString(valueString, point.x - valueStringBox.width - 3, point.y + 3);
        } else if (width/2 > point.x && fixheight/2 < point.y) {//左下
            base64DrawBitmapString(valueString, point.x + 3, point.y - valueStringBox.height - 3);
        } else {//右下
            base64DrawBitmapString(valueString, point.x - valueStringBox.width - 3, point.y - valueStringBox.height - 3);
        }
        
        if (bSecondPoint) {
            ofSetHexColor(0xFFFF00);
            char valueString2[64];
            std::sprintf(valueString2,"( %.2f , %.2f )",(*value2).x, (*value2).y);
            ofRectangle valueStringBox2 = base64GetStringBoundingBox(valueString2);
            if (width/2 > point2.x && fixheight/2 > (point2.y - y)){
                base64DrawBitmapString(valueString2, point2.x + 3, point2.y + 3);
            } else if (width/2 < point2.x && fixheight/2 > (point2.y)) {//右上
                base64DrawBitmapString(valueString2, point2.x - valueStringBox2.width - 3, point2.y + 3);
            } else if (width/2 > point2.x && fixheight/2 < point2.y) {//左下
                base64DrawBitmapString(valueString2, point2.x + 3, point2.y - valueStringBox2.height - 3);
            } else {//右下
                base64DrawBitmapString(valueString2, point2.x - valueStringBox2.width - 3, point2.y - valueStringBox2.height - 3);
            }
        }
    }
    ofTranslate(0, 0 - (int)sliderTextHeight);
    fixButtonDrawOfContentSlider2d();
    
    if (!fixed) {
        ofFill();
        ofSetHexColor(config->emptyColor);
        ofRect(secBtnPos.x, 1.0f, secondPointBoxWidth, secondPointBoxWidth);
        ofSetHexColor(0xFFFF00);
    }
    else {
        ofSetHexColor(config->borderColor);
        ofNoFill();
    }
    ofSetLineWidth(0.5);
    if (bSecondPoint) {
        ofFill();
    } else ofNoFill();
    ofCircle(secBtnPos.x + secondPointBoxWidth / 2.0f, secondPointBoxWidth / 2 + 1.0f, secondPointBoxWidth / 2);
    ofNoFill();
    ofSetHexColor(config->borderColor);
    ofRect(secBtnPos.x - 0.5, 0.5f, secondPointBoxWidth + 1.0f, secondPointBoxWidth + 1.0f);
    
    
	glPopMatrix();
	ofDisableAlphaBlending();
	
}