Exemplo n.º 1
0
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Transfers head of source queue to destination queue
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
void print_Scheduler(Scheduler_p sch){
    printf("Current Status of Scheduler\n");
    print_FIFO_queue(sch->new_queue);
    //print_FIFO_queue(sch->ready_queue);
    print_priority_queue(sch->priority_ready_queue);
    print_FIFO_queue(sch->running_queue);
    print_FIFO_queue(sch->interrupted_queue);
    print_FIFO_queue(sch->io_1_waiting_queue);
    print_FIFO_queue(sch->io_2_waiting_queue);
    print_FIFO_queue(sch->terminated_queue);
}
Exemplo n.º 2
0
int a_star_search(search_node * root, lifo ** path)
{
    search_node * node = root;
    
    #if DEBUG
        god_mode_debug("Creating new priority queue\n");
    #endif
    lifo closed_set;
    init_lifo_queue(&closed_set);
    
    priority_queue queue;
    init_priority_queue(&queue);
    #if DEBUG
        god_mode_debug("Adding first entry to priority queue\n");
    #endif
    pq_add_entry(&queue, root, h(root));
    
    while (queue.total_entries > 0)
    {        
        #if DEBUG
        god_mode_debug("\n----------------\nNew iteration\n----------------\n");
        print_lifo_queue(&closed_set);        
        print_priority_queue(&queue);
        god_mode_debug("Expanding node\n");
        #endif
        node = queue.head->node;
        
        #if DEBUG
        draw_node(node);
        #endif
        if (expand_node(&queue, &closed_set) == 1)
        {
            #if DEBUG
            god_mode_debug("Goal node found\n");
            #endif
            *path = recover_path(node);
            if (*path == NULL)
            {
                #if DEBUG
                god_mode_debug("unable to recover path\n");
                #endif
                return -1;
            }
            sprintf(str, "%d expanded_nodes\n%d nodes in closed set\n%d nodes in open set\n", closed_set.total_entries + 1, closed_set.total_entries, queue.total_entries);
            god_mode_debug(str);
            god_mode_debug("Returning solution\n");  
            //printf("%d expanded_nodes\n%d nodes in closed set\n%d nodes in open set\n", closed_set.total_entries + 1, closed_set.total_entries, queue.total_entries);
            
            return 0;
        }
    }
    // Solution not found
    return -2;
}
Exemplo n.º 3
0
int main()
{
    int *a;
    int heap_size = 0;
    char ch, buffer[512];
    int key, index, min, size;
    
    printf("Enter size of the priority queue: ");
    fgets(buffer, 511, stdin);
    sscanf(buffer, "%d", &size);
    
    a = (int *) malloc(sizeof(int) * size);
    
    do
    {
        printf("1> Enter i to insert a number in priority queue\n");
        printf("2> Enter c to delete a number from priority queue\n");
        printf("3> Enter d to decrease key\n");
        printf("4> Enter g to see minimum value in priority queue\n");
        printf("5> Enter m to retrieve maximum value in priority queue\n");
        printf("6> Enter p to print the priority queue\n");
        printf("7> Enter e to exit\n");
        fgets(buffer, 511, stdin);
        sscanf(buffer, "%c", &ch);
        switch(ch)
        {
            case 'i':
                if(heap_size < size)
                {
                    printf("Enter the key to insert: ");
                    fgets(buffer, 511, stdin);
                    sscanf(buffer, "%d", &key);
                    insert(a, key, &heap_size);
                    printf("Key inserted successfully\n");
                }
                else
                    printf("Priority queue overflow\n");
                break;
            case 'c':
                printf("Enter index to delete: ");
                fgets(buffer, 511, stdin);
                sscanf(buffer, "%d", &index);
                if(delete(a, index, &heap_size) != -1)
                    printf("Key deleted successfully\n");
                break;
            case 'd':
                printf("Enter index to be decrease: ");
                fgets(buffer, 511, stdin);
                sscanf(buffer, "%d", &index);
                printf("Enter new key less than the previous: ");
                fgets(buffer, 511, stdin);
                sscanf(buffer, "%d", &key);
                decrease_key(a, index, key, heap_size);
                printf("Key decreased successfully\n");
                break;
            case 'g':
                min = minimum(a, heap_size);
                if(min != -1)
                    printf("Minimum value in priority queue = %d\n", min);
                break;
            case 'm':
                min = extract_minimum(a, &heap_size);
                if(min != -1)
                    printf("Minimum value in priority queue = %d\n", min);
                break;
            case 'p':
                print_priority_queue(a, heap_size);
                break;
            case 'e':
                printf("Exiting\n");
                break;
            default:
                printf("Try again\n");
                break;
        }
    }
    while(ch != 'e');
    
    return 1;
}