src/puzzle.cpp
/*  process to find a nested chain in dynamic mode (level 4)
    looking for forcing or contradiction
    only basic strong and weak links
	but dynamic search (using basic sets)

*/
process to find a nested chain in dynamic mode (level 4)
looking for forcing or contradiction
only basic strong and weak links
but dynamic search (using basic sets)
process to find a nested chain in dynamic mode ( level 4 ) looking for forcing or contradiction only basic strong and weak links but dynamic search ( using basic sets )
int PUZZLE::CaseNestedLevel4Case1( USHORT tag )  {
	if(0) {
		EE.E("\n\nnested level 4 case 1 for tag ");
		zpln.ImageTag(tag);
		EE.Enl();
	}
	chain4_to = chain4_dpn.t; 
	for(int i = 0; i < 640; i++)
		chain4_tsets[i] = 0;
	chain4_npas = 0;
	chain4_steps[0]=(*cum);  
	chain4_steps[0].Set(tag);  
	chain4_allsteps = chain4_cumsteps[0] = chain4_steps[0];  
	chain4_buf[0]=tag;        
	chain4_tx[0] = chain4_buf;
	chain4_itx[0] = 1; 
	nested_aig2 = 1;
	while(nested_aig2 && chain4_npas++ <= pasmax) {
		nested_aig2=0; 
		chain4_cum = &chain4_cumsteps[chain4_npas-1];
		chain4_step = &chain4_steps[chain4_npas];
		chain4_ta = chain4_tx[chain4_npas-1];
		chain4_ita = chain4_itx[chain4_npas-1];
		chain4_tx[chain4_npas]=&chain4_ta[chain4_ita];
		NestedChainWhile(tag);                    
		if(!nested_aig2)
			return 0;			
		chain4_cumsteps[chain4_npas] = chain4_allsteps;   
		(*chain4_step) = chain4_allsteps;
		(*chain4_step)-=(*chain4_cum);  
		(*chain4_step).String(chain4_tx[chain4_npas],chain4_itx[chain4_npas] );
        if(0){  
		  EE.E(chain4_npas);EE.E("pas ncase lvl4 ");Image((*chain4_step),"step",0);
		  Image(chain4_allsteps,"chain4_allsteps",0);
		  Image(allsteps,"allsteps",0);
		  EE.Enl();
		}
	    if((*chain4_step).IsEmpty() ||chain4_npas>30 ){
        EE.Enl("check if null or 30 pas");
		return 0;
		}
		BFTAG tw(chain4_allsteps);
		tw &=(tw.Inverse()).TrueState();
		USHORT ttw[640],ittw;
		tw.String(ttw,ittw);
		if(!ittw)
			continue; 
		if(0){ 
               EE.Enl("contradiction reached step"); EE.Enl( chain4_npas);
			   Image(tw,"for targets",0);			  
			}
		USHORT totlength=10000;
	    for(int iw=0;iw<ittw;iw++){
			USHORT y=ttw[iw]^1; 
			USHORT itt=NestedChainGoBack(y);
			if(itt<2) continue; 
			chain4_bf=back4_bfsource;
			y^=1;
			if(y==tag){   
			   USHORT length=chain4_iresult-1;
			   if(length<totlength){ 
				   totlength=length;
				   USHORT im = tstore.AddOne(chain4_result,chain4_iresult);
				   tsets[tag ^ 1] =- tcandgo.itt;
				   tcandgo.tt[tcandgo.itt++].Add(im, chain4_bf,length); 
			   }
				continue;
			}
			USHORT length=chain4_iresult;
			USHORT  ii=tstore.AddChain(chain4_result,chain4_iresult);
			itt=NestedChainGoBack(y); 
			if(!itt) continue; 
			length+=chain4_iresult; 
			chain4_bf|=back4_bfsource;  
			if(length<totlength){ 
				totlength=length;
				USHORT  jj=tstore.AddChain(chain4_result,chain4_iresult);
			    USHORT im = tstore.AddMul(ii, jj);
			    tsets[tag^1] =- tcandgo.itt;
				tcandgo.tt[tcandgo.itt++].Add(im, chain4_bf,length); 
			}
		}
		if(0 && totlength<10000 ){
			EE.E("\n\nnested level 4 case 1 for tag ");
			zpln.ImageTag(tag);
			EE.E("cleared length ");
			EE.Enl(totlength);
		}
		return (totlength<10000);
	}
	return 0;
}
int PUZZLE :: CaseNestedLevel4Case1 ( USHORT tag ) { if ( 0 ) { EE . E ( " \n \n " ) ; zpln . ImageTag ( tag ) ; EE . Enl ( ) ; } chain4_to = chain4_dpn . t ; for ( int i = 0 ; i < 640 ; i ++ ) chain4_tsets [ i ] = 0 ; chain4_npas = 0 ; chain4_steps [ 0 ] = ( * cum ) ; chain4_steps [ 0 ] . Set ( tag ) ; chain4_allsteps = chain4_cumsteps [ 0 ] = chain4_steps [ 0 ] ; chain4_buf [ 0 ] = tag ; chain4_tx [ 0 ] = chain4_buf ; chain4_itx [ 0 ] = 1 ; nested_aig2 = 1 ; while ( nested_aig2 && chain4_npas ++ <= pasmax ) { nested_aig2 = 0 ; chain4_cum = & chain4_cumsteps [ chain4_npas - 1 ] ; chain4_step = & chain4_steps [ chain4_npas ] ; chain4_ta = chain4_tx [ chain4_npas - 1 ] ; chain4_ita = chain4_itx [ chain4_npas - 1 ] ; chain4_tx [ chain4_npas ] = & chain4_ta [ chain4_ita ] ; NestedChainWhile ( tag ) ; if ( ! nested_aig2 ) return 0 ; chain4_cumsteps [ chain4_npas ] = chain4_allsteps ; ( * chain4_step ) = chain4_allsteps ; ( * chain4_step ) -= ( * chain4_cum ) ; ( * chain4_step ) . String ( chain4_tx [ chain4_npas ] , chain4_itx [ chain4_npas ] ) ; if ( 0 ) { EE . E ( chain4_npas ) ; EE . E ( " " ) ; Image ( ( * chain4_step ) , " " , 0 ) ; Image ( chain4_allsteps , " " , 0 ) ; Image ( allsteps , " " , 0 ) ; EE . Enl ( ) ; } if ( ( * chain4_step ) . IsEmpty ( ) || chain4_npas > 30 ) { EE . Enl ( " " ) ; return 0 ; } BFTAG tw ( chain4_allsteps ) ; tw &= ( tw . Inverse ( ) ) . TrueState ( ) ; USHORT ttw [ 640 ] , ittw ; tw . String ( ttw , ittw ) ; if ( ! ittw ) continue ; if ( 0 ) { EE . Enl ( " " ) ; EE . Enl ( chain4_npas ) ; Image ( tw , " " , 0 ) ; } USHORT totlength = 10000 ; for ( int iw = 0 ; iw < ittw ; iw ++ ) { USHORT y = ttw [ iw ] ^ 1 ; USHORT itt = NestedChainGoBack ( y ) ; if ( itt < 2 ) continue ; chain4_bf = back4_bfsource ; y ^= 1 ; if ( y == tag ) { USHORT length = chain4_iresult - 1 ; if ( length < totlength ) { totlength = length ; USHORT im = tstore . AddOne ( chain4_result , chain4_iresult ) ; tsets [ tag ^ 1 ] = - tcandgo . itt ; tcandgo . tt [ tcandgo . itt ++ ] . Add ( im , chain4_bf , length ) ; } continue ; } USHORT length = chain4_iresult ; USHORT ii = tstore . AddChain ( chain4_result , chain4_iresult ) ; itt = NestedChainGoBack ( y ) ; if ( ! itt ) continue ; length += chain4_iresult ; chain4_bf |= back4_bfsource ; if ( length < totlength ) { totlength = length ; USHORT jj = tstore . AddChain ( chain4_result , chain4_iresult ) ; USHORT im = tstore . AddMul ( ii , jj ) ; tsets [ tag ^ 1 ] = - tcandgo . itt ; tcandgo . tt [ tcandgo . itt ++ ] . Add ( im , chain4_bf , length ) ; } } if ( 0 && totlength < 10000 ) { EE . E ( " \n \n " ) ; zpln . ImageTag ( tag ) ; EE . E ( " " ) ; EE . Enl ( totlength ) ; } return ( totlength < 10000 ) ; } return 0 ; }
process to find a nested chain in dynamic mode (level 4)
looking for forcing or contradiction
only basic strong and weak links
but dynamic search (using basic sets)
process to find a nested chain in dynamic mode ( level 4 ) looking for forcing or contradiction only basic strong and weak links but dynamic search ( using basic sets )
// we use the table  for nested // start with the known status // plus the tag // and expand the tag in cycle one // initial is tag to go forward //--------------------- loop  forward // while cycle // nothing happenned finished should not be // stop at the first contradiction reached // now we have a contradicton or a forcing chain // we don't look for more // we have to take the shortest forcing or contradiction chain // start with false for forcing chain // should always be ok if 1, target already false, don't do // now y is true and can be the tag //this is a forcing chain its ok // take it if lower //   elims.Set(i ^ 1);  // second chain // should always be ok // add second length // and new source // take it if lower // end while