Exemplo n.º 1
0
        protected override bool SLayer(SolverParams SolParams)
        {
            //var LIndex = SolParams.lastNotEmptyLayerIndex;
            var ret = true;
            int ActiveBlocksCount = 0;

            //var BIndex = SolParams.BIndex;
            if (SolParams.BIndex == -1)
            {
                SolParams.BIndex = 0;
                for (; SolParams.BIndex < SolParams.Way.layers[SolParams.lastNotEmptyLayerIndex].blocks.Count; SolParams.BIndex++)
                {
                    var WayBlock = SolParams.Way.layers[SolParams.lastNotEmptyLayerIndex].blocks[SolParams.BIndex];
                    if (!WayBlock.active_inputs.All(x => !x))
                    {
                        ActiveBlocksCount++;
                        continue;
                    }
                }
                if (ActiveBlocksCount > SolParams.MaxActiveBlocksOnLayer)
                {
                    return(false);
                }
                SolParams.BIndex = 0;
            }
            for (; SolParams.BIndex < SolParams.Way.layers[SolParams.lastNotEmptyLayerIndex].blocks.Count; SolParams.BIndex++)
            {
                var WayBlock = SolParams.Way.layers[SolParams.lastNotEmptyLayerIndex].blocks[SolParams.BIndex];
                if (WayBlock.active_inputs.All(x => !x))
                {
                    continue;
                }
                if (!WayBlock.active_outputs.All(x => !x))
                {
                    //ActiveBlocksCount++;
                    continue; //already solved block
                }
                ret = false;
                var NetBlock = SolParams.Net.GetLayers()[SolParams.lastNotEmptyLayerIndex].GetBlocks()[SolParams.BIndex];
                var Params   = new BlockStateExtrParams(WayBlock.active_inputs, null, SolParams.Net.GetMultiThreadPrevalence(), SolParams.P, SolParams.Type, true);
                var States   = NetBlock.ExtractStates(Params);
                if (States.Count > 0)
                {
                    var State    = States[0];
                    var NewWay   = WayConverter.CloneWay(SolParams.Way);
                    var NewBLock = NewWay.layers[SolParams.lastNotEmptyLayerIndex].blocks[SolParams.BIndex];
                    NewBLock.active_outputs = State._outputs;
                    NewWay.layers[SolParams.lastNotEmptyLayerIndex].blocks[SolParams.BIndex] = NewBLock;
                    var NewSolParams = SolParams;
                    NewSolParams.P  *= State.MatrixValue;
                    NewSolParams.Way = NewWay;
                    NewSolParams.BIndex++;
                    Solve(NewSolParams);
                }
                break;
            }
            return(ret);
        }
Exemplo n.º 2
0
        protected virtual void PLayer(SolverParams SolParams)
        {
            var LIndex = SolParams.lastNotEmptyLayerIndex;
            var Params = new BlockStateExtrParams(SolParams.Way.layers[LIndex].blocks[0].active_inputs, null,
                                                  new Prevalence(), new Prevalence(), SolParams.Type);
            var States = SolParams.Net.GetLayers()[LIndex].GetBlocks()[0].ExtractStates(Params);

            if (States.Count == 1)
            {
                //deep copying
                foreach (var j in Enumerable.Range(0, SolParams.Way.layers[LIndex].blocks[0].active_outputs.Count))
                {
                    SolParams.Way.layers[LIndex].blocks[0].active_outputs[j] = States[0]._outputs[j];
                }
            }
            else
            {
                Logger.UltraLogger.Instance.AddToLog("BaseSolver: Cant extract state from P-layer", Logger.MsgType.Error);
                throw new NotImplementedException();
            }
        }
Exemplo n.º 3
0
        public override List <BlockState> ExtractStates(BlockStateExtrParams Params)// MIN prevalence, current inputs
        {
            var ret    = new List <BlockState>();
            var States = (Params.Type == AnalisysType.Linear) ? LStates : DStates;
            var Count  = States.Count;

            for (int i = 0; i < Count; i++)
            {
                var state = States[i];
                var P     = state.MatrixValue * Params.CurrentPrevalence;
                if (((P >= Params.MIN) && (P.Numerator != 0)) || (!Params.CheckPrevalence))
                {
                    if (Enumerable.Range(0, state._inputs.Count).All(x => (state._inputs[x] == Params.Inputs[x])))
                    {
                        ret.Add(state);
                    }
                }
                else
                {
                    break;
                }
            }
            return(ret);
        }
Exemplo n.º 4
0
        public override List <BlockState> ExtractStates(BlockStateExtrParams Params)
        {
            var State = new BlockState(Params.Inputs);
            var ret   = new List <BlockState>(1);

            foreach (var j in Enumerable.Range(0, _length))
            {
                if (State._inputs[j] != false)
                {
                    var Num = GetOutputNumber(j);
                    if (Num < _length)
                    {
                        State._outputs[Num] = true;
                    }
                    else
                    {
                        Logger.UltraLogger.Instance.AddToLog("Net: Wrong pblock initializaion", Logger.MsgType.Error);
                        throw new NotImplementedException();
                    }
                }
            }
            ret.Add(State);
            return(ret);
        }
Exemplo n.º 5
0
 public override List <BlockState> ExtractStates(BlockStateExtrParams Params)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 public abstract void Init(List <byte> arg); //SBlock size:4-8. Whole word: up to 64bit.
 public abstract List <BlockState> ExtractStates(BlockStateExtrParams Params);