Exemplo n.º 1
0
Arquivo: main.c Projeto: ShabbyX/shDS
int main(int argc, char **argv)
{
	bool good = true;

	srand(time(NULL));
	if (argc < 2)
	{
		if (generate_data(RANDOM_SIZE))
			goto exit_no_mem;
	}
	else
	{
		if (read_data(argv[1]))
			goto exit_bad_input;
	}

	good = good && test_init() == 0;
	good = good && test_append() == 0;
	good = good && test_duplicate() == 0;
	good = good && test_links() == 0;
	good = good && test_prepend() == 0;
	good = good && test_links() == 0;
	good = good && test_concat() == 0;
	good = good && test_links() == 0;
	good = good && test_break() == 0;
	good = good && test_links() == 0;
	good = good && test_insert() == 0;
	good = good && test_links() == 0;
	good = good && test_compare() == 0;
	good = good && test_delete() == 0;
	good = good && test_links() == 0;
	good = good && test_clear() == 0;
	good = good && test_free() == 0;

	cleanup_data();

	return good?EXIT_SUCCESS:EXIT_FAILURE;
exit_bad_input:
exit_no_mem:
	cleanup_data();
	return EXIT_FAILURE;
}
/* *********************************************************************
   Expands the tree from the given node until i_max_sim_steps_per_frame
   is reached
	
   ******************************************************************* */
void UniformCostSearch::expand_tree(TreeNode* start_node) {
	// If the root is terminal, we will not expand any of its children; deal with this
	//  appropriately
	if (start_node->is_terminal) {
		set_terminal_root(start_node);
		return;
	}

	std::priority_queue<TreeNode*, std::vector<TreeNode*>, TreeNodeComparer > q;
	q.push(start_node);

	int num_simulated_steps = 0;
	int num_actions = available_actions.size();

	m_expanded_nodes = 0;
	m_generated_nodes = 0;

	m_pruned_nodes = 0;

	while(!q.empty()) {
		// Pop a node to expand
		TreeNode* curr_node = q.top();
		q.pop();
       
		bool leaf_node = (curr_node->v_children.empty());
		m_expanded_nodes++;
		// Expand all of its children (simulates the result)
		for (int a = 0; a < num_actions; a++) {
			Action act = available_actions[a];
	
		    	TreeNode * child;

			// If re-expanding an internal node, don't creates new nodes
			if (leaf_node) {
				m_generated_nodes++;
				child = new TreeNode(curr_node,	
						curr_node->state,
						this,
						act,
						sim_steps_per_node); 
				// Miquel: Let's fix C = 10000
				child->fn += ( m_max_reward - child->accumulated_reward ); // Miquel: add this to obtain Hector's BFS + m_max_reward * (720 - child->depth()) ;

				// TODO: UniformCostSearch needs to be split into two classes
				// the new one encapsulating the novelty-based search algorithm
				if (child->depth() > m_max_depth ) m_max_depth = child->depth();
				num_simulated_steps += child->num_simulated_steps;
				
				curr_node->v_children.push_back(child);
			}
			else {
				child = curr_node->v_children[a];
				if ( !child->is_terminal )
					num_simulated_steps += child->num_simulated_steps;

		
			}

			// Don't expand duplicate nodes, or terminal nodes
			if (!child->is_terminal) {
				if (! (ignore_duplicates && test_duplicate(child)) )
					q.push(child);
			}
		}
	
		// Stop once we have simulated a maximum number of steps
		if (num_simulated_steps >= max_sim_steps_per_frame) {
			break;
		}
		
	}
    
	if (q.empty()) std::cout << "Search Space Exhausted!" << std::endl;

	
	update_branch_return(start_node);
}
int BestFirstSearch::expand_node(TreeNode* curr_node) {
	int num_simulated_steps = 0;
	int num_actions = available_actions.size();
	bool leaf_node = (curr_node->v_children.empty());
	m_expanded_nodes++;
	if (curr_node->novelty == 1)
		m_exp_count_novelty1++;
	else
		m_exp_count_novelty2++;
	// Expand all of its children (simulates the result)	
	if (leaf_node) {
		curr_node->v_children.resize(num_actions);
		curr_node->available_actions = available_actions;
		if (m_randomize_successor)
			std::random_shuffle(curr_node->available_actions.begin(),
					curr_node->available_actions.end());

	}

	for (int a = 0; a < num_actions; a++) {
		Action act = curr_node->available_actions[a];

		TreeNode * child;
		// If re-expanding an internal node, don't creates new nodes
		if (leaf_node) {
			m_generated_nodes++;
			child = new TreeNode(curr_node, curr_node->state, this, act,
					sim_steps_per_node, discount_factor);

			if (check_novelty_1(child->state)) {
				update_novelty_table(child->state);
				child->novelty = 1;
				m_gen_count_novelty1++;
			} else {
				child->novelty = 2;
				m_gen_count_novelty2++;
			}
			child->fn += (m_max_reward - child->discounted_accumulated_reward); // Miquel: add this to obtain Hector's BFS + m_max_reward * (720 - child->depth()) ;

			child->num_nodes_reusable = curr_node->num_nodes_reusable
					+ num_actions;

			if (child->depth() > m_max_depth)
				m_max_depth = child->depth();
			num_simulated_steps += child->num_simulated_steps;

			curr_node->v_children[a] = child;

		} else {

			child = curr_node->v_children[a];
			m_pruned_nodes++;
			// This recreates the novelty table (which gets resetted every time
			// we change the root of the search tree)
			if (m_novelty_pruning) {
				if (check_novelty_1(child->state)) {
					update_novelty_table(child->state);
					child->novelty = 1;
					m_gen_count_novelty1++;
				} else {
					child->novelty = 2;
					m_gen_count_novelty2++;

				}
			}

			child->updateTreeNode();
			child->fn += (m_max_reward - child->discounted_accumulated_reward); // Miquel: add this to obtain Hector's BFS + m_max_reward * (720 - child->depth()) ;

			if (child->depth() > m_max_depth)
				m_max_depth = child->depth();

			num_simulated_steps += child->num_simulated_steps;
		}

		// // Don't expand duplicate nodes, or terminal nodes
		if (!child->is_terminal) {
			if (!(ignore_duplicates && test_duplicate(child))) {
				if (child->fn != m_max_reward)
					q_exploitation->push(child);
				else
					q_exploration->push(child);
			}
		}

	}

	curr_node->already_expanded = true;
	return num_simulated_steps;
}
int BestFirstSearch::reuse_branch(TreeNode* node) {
	int num_simulated_steps = 0;

	node->updateTreeNode();
	update_novelty_table(node->state);

	queue<TreeNode*> q;
	q.push(node);

	while (!q.empty()) {
		// Pop a node to expand
		TreeNode* curr_node = q.front();
		q.pop();

		if (curr_node->depth() > m_reward_horizon - 1)
			continue;
		if (!node->v_children.empty()) {
			for (size_t c = 0; c < node->v_children.size(); c++) {
				TreeNode* child = curr_node->v_children[c];

				// This recreates the novelty table (which gets resetted every time
				// we change the root of the search tree)
				if (m_novelty_pruning) {

					if (check_novelty_1(child->state)) {
						update_novelty_table(child->state);
						if (!child->already_expanded) {
							child->novelty = 1;
						}
					} else {
						if (!child->already_expanded)
							child->novelty = 2;

					}

				}

				child->updateTreeNode();
				child->fn += (m_max_reward
						- child->discounted_accumulated_reward); // Miquel: add this to obtain Hector's BFS + m_max_reward * (720 - child->depth()) ;

				//First applicable action
				if (child->depth() == 1)
					child->num_nodes_reusable = child->num_nodes();
				else
					child->num_nodes_reusable = curr_node->num_nodes_reusable;
				if (child->depth() > m_max_depth)
					m_max_depth = child->depth();

				num_simulated_steps += child->num_simulated_steps;

				// Don't expand duplicate nodes, or terminal nodes
				if (!child->is_terminal) {
					if (!(ignore_duplicates && test_duplicate(child))) {
						if (!child->already_expanded) {
							if (child->fn != m_max_reward)
								q_exploitation->push(child);

							q_exploration->push(child);

						} else
							q.push(child);

					}
				}

			}
		}
		// // Stop once we have simulated a maximum number of steps
		// if (num_simulated_steps >= max_sim_steps_per_frame) {
		// 	break;
		// }

	}

	return num_simulated_steps;

}
Exemplo n.º 5
0
void    scr_label( void )
{
    condcode        cc;
    getnum_block    gn;
    labelcb     *   lb;
    char            linestr[MAX_L_AS_STR];

    scan_start += 2;                    // over dots

    while( *scan_start == ' ' ) {       // may be ...LABEL or ...      LABEL
        scan_start++;                   // over blanks
    }
    if( *scan_start == '\0'  ) {        // no label?
        scan_err = true;
        err_count++;
        g_err( err_missing_name, "" );
        if( input_cbs->fmflags & II_tag_mac ) {
            utoa( input_cbs->s.m->lineno, linestr, 10 );
            g_info( inf_mac_line, linestr, input_cbs->s.m->mac->name );
        } else {
            utoa( input_cbs->s.f->lineno, linestr, 10 );
            g_info( inf_file_line, linestr, input_cbs->s.f->filename );
        }
        show_include_stack();
        return;
    } else {

        gn.argstart      = scan_start;
        gn.argstop       = scan_stop;
        gn.ignore_blanks = 0;

        cc = getnum( &gn );             // try numeric expression evaluation
        if( cc == pos ) {               // numeric linenumber

            scan_start = gn.argstart;   // start for next token

            // check if lineno from label matches actual lineno

            if( input_cbs->fmflags & II_tag_mac ) {
                if( gn.result != input_cbs->s.m->lineno ) {
                    scan_err = true;
                    err_count++;
                    g_err( err_label_line, gn.resultstr );
                    utoa( input_cbs->s.m->lineno, linestr, 10 );
                    g_info( inf_mac_line, linestr, input_cbs->s.m->mac->name );
                    show_include_stack();
                    return;
                }
            } else {
                if( gn.result != input_cbs->s.f->lineno ) {
                    scan_err = true;
                    err_count++;
                    g_err( err_label_line, gn.resultstr );
                    utoa( input_cbs->s.f->lineno, linestr, 10 );
                    g_info( inf_file_line, linestr, input_cbs->s.f->filename );
                    show_include_stack();
                    return;
                }
            }

            if( input_cbs->fmflags & II_tag_mac ) {
                  // numeric macro label no need to store
            } else {
                wng_count++;
                g_warn( wng_label_num );
                utoa( input_cbs->s.f->lineno, linestr, 10 );
                g_info( inf_file_line, linestr, input_cbs->s.f->filename );
                show_include_stack();
            }

        } else {                        // no numeric label
            cc = getarg();
            if( cc == pos ) {           // label name specefied
                char    *   p;
                char    *   pt;
                int         len;

                p   = tok_start;
                pt  = token_buf;
                len = 0;
                while( len < arg_flen ) {   // copy to buffer
                    *pt++ = *p++;
                    len++;
                }
                *pt = '\0';
                if( len >  MAC_NAME_LENGTH ) {
                    err_count++;
                    g_err( err_sym_long, token_buf );
                    utoa( input_cbs->s.f->lineno, linestr, 10 );
                    g_info( inf_file_line, linestr, input_cbs->s.f->filename );
                    show_include_stack();
                    token_buf[MAC_NAME_LENGTH] = '\0';
                }

                if( input_cbs->fmflags & II_tag_mac ) {

                    cc = test_duplicate( token_buf, input_cbs->s.m->lineno );
                    if( cc == pos ) {   // ok name and lineno match
                        // nothing to do
                    } else {
                        if( cc == neg ) {   // name with different lineno
                            scan_err = true;
                            err_count++;
                            g_err( err_label_dup, token_buf );
                            utoa( input_cbs->s.m->lineno, linestr, 10 );
                            g_info( inf_mac_line, linestr,
                                     input_cbs->s.m->mac->name );
                            show_include_stack();
                            return;
                        } else {        // new label
                            lb              = mem_alloc( sizeof( labelcb ) );
                            lb->prev        = input_cbs->s.m->mac->label_cb;
                            input_cbs->s.m->mac->label_cb = lb;
                            lb->pos         = 0;
                            lb->lineno      = input_cbs->s.m->lineno;
                            strcpy_s( lb->label_name, sizeof( lb->label_name ),
                                      token_buf );
                        }
                    }
                } else {
                    cc = test_duplicate( token_buf, input_cbs->s.f->lineno );
                    if( cc == pos ) {   // ok name and lineno match
                        // nothing to do
                    } else {
                        if( cc == neg ) {   // name with different lineno
                            scan_err = true;
                            err_count++;
                            g_err( err_label_dup, token_buf );
                            utoa( input_cbs->s.f->lineno, linestr, 10 );
                            g_info( inf_file_line, linestr,
                                    input_cbs->s.f->filename );
                            show_include_stack();
                            return;
                        } else {        // new label

                            lb              = mem_alloc( sizeof( labelcb ) );
                            lb->prev        = input_cbs->s.f->label_cb;
                            input_cbs->s.f->label_cb = lb;
                            lb->pos         = input_cbs->s.f->pos;
                            lb->lineno      = input_cbs->s.f->lineno;
                            strcpy_s( lb->label_name, sizeof( lb->label_name ),
                                      token_buf );
                        }
                    }
                }
            } else {
                scan_err = true;
                err_count++;
                g_err( err_missing_name, "" );
                if( input_cbs->fmflags & II_tag_mac ) {
                    utoa( input_cbs->s.m->lineno, linestr, 10 );
                    g_info( inf_mac_line, linestr, input_cbs->s.m->mac->name );
                } else {
                    utoa( input_cbs->s.f->lineno, linestr, 10 );
                    g_info( inf_file_line, linestr, input_cbs->s.f->filename );
                }
                show_include_stack();
                return;
            }
        }

        if( *scan_start == ' ' ) {
            scan_start++;               // skip one blank

            if( *scan_start ) {         // rest of line is not empty
                split_input( buff2, scan_start, false );// split and process next
            }
        }
        scan_restart = scan_stop + 1;
        return;
    }
}
/* *********************************************************************
   Expands the tree from the given node until i_max_sim_steps_per_frame
   is reached
	
   ******************************************************************* */
void BreadthFirstSearch::expand_tree(TreeNode* start_node) {
	// If the root is terminal, we will not expand any of its children; deal with this
	//  appropriately
	if (start_node->is_terminal) {
		set_terminal_root(start_node);
		return;
	}

	queue<TreeNode*> q;
	q.push(start_node);

	int num_simulated_steps = 0;
	int num_actions = available_actions.size();

	m_expanded_nodes = 0;
	m_generated_nodes = 0;

	m_pruned_nodes = 0;

	while(!q.empty()) {
		// Pop a node to expand
		TreeNode* curr_node = q.front();
		q.pop();
	
       
		bool leaf_node = (curr_node->v_children.empty());
		m_expanded_nodes++;
		// Expand all of its children (simulates the result)

		if(m_randomize_successor)
			std::random_shuffle ( available_actions.begin(), available_actions.end() );
		if(leaf_node){
			curr_node->v_children.resize( num_actions );
			curr_node->available_actions = available_actions;
		}
		for (int a = 0; a < num_actions; a++) {
			Action act = available_actions[a];
	
		    	TreeNode * child;

			// If re-expanding an internal node, don't creates new nodes
			if (leaf_node) {
				m_generated_nodes++;
				child = new TreeNode(curr_node,	
						curr_node->state,
						this,
						act,
						sim_steps_per_node); 

				// TODO: BreadthFirstSearch needs to be split into two classes
				// the new one encapsulating the novelty-based search algorithm
				if (child->depth() > m_max_depth ) m_max_depth = child->depth();
				num_simulated_steps += child->num_simulated_steps;
				
				curr_node->v_children[a] = child;
			}
			else {
				child = curr_node->v_children[a];
				if ( !child->is_terminal )
					num_simulated_steps += child->num_simulated_steps;

		
			}

			// Don't expand duplicate nodes, or terminal nodes
			if (!child->is_terminal) {
				if (! (ignore_duplicates && test_duplicate(child)) )
					q.push(child);
			}
		}
	
		// Stop once we have simulated a maximum number of steps
		if (num_simulated_steps >= max_sim_steps_per_frame) {
			break;
		}
		
	}
    
	if (q.empty()) std::cout << "Search Space Exhausted!" << std::endl;

	
	update_branch_return(start_node);
}
Exemplo n.º 7
0
BOOL CMultiApp::InitInstance()
{
  one a;
  //two b;
  //b.test();

  // testSmartPtrs();
	test_duplicate();
  /*testFunctors();
  test_decorator();*/
  /*testLambada();
  testTemplates();
  testGarbageCollector();
  test_tuple();*/

  //int tt = 7;
  //int* a = &tt;
  //int*b = &tt;

  
 //multiThreadTest();

  // stringTest();

 // stackTest();


 // testBFS();
 // testDFS();

 // binaryTreeTest();

 // subProcessTest();

 // multiThreadingTest();

 // oddEvenTest();

  producerConsumerTest();

  excel_column_converter(std::string("AA"));
  excel_column_converter(std::string("27"));


  // other method for odd even printing ... doesn't work... 
  // {
  //InitializeCriticalSection(&cs);

  //_beginthreadex(NULL, NULL, even_thread_cs, 0,0, 0);
  //_beginthreadex(NULL, NULL, odd_thread_cs, 0,0, 0);

  //getchar();
  //}

  return TRUE;

  

	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinAppEx::InitInstance();


	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	EnableTaskbarInteraction(FALSE);

	// AfxInitRichEdit2() is required to use RichEdit control	
	// AfxInitRichEdit2();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)


	InitContextMenuManager();

	InitKeyboardManager();

	InitTooltipManager();
	CMFCToolTipInfo ttParams;
	ttParams.m_bVislManagerTheme = TRUE;
	theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
		RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CMultiDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CMultiView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);


	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);



	// Dispatch commands specified on the command line.  Will return FALSE if
	// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	// call DragAcceptFiles only if there's a suffix
	//  In an SDI app, this should occur after ProcessShellCommand
	return TRUE;
}