Artificial Intelligence Problem: Please answer ALL PARTS OF THE QUESTION with FU
ID: 3601280 • Letter: A
Question
Artificial Intelligence Problem: Please answer ALL PARTS OF THE QUESTION with FULL EXPLANATIONS. Thanks! Problem 2.2 (15 points) Alpha-Beta Pruning Construct a tree with a branching factor of 3 at each level, and 81 leaves. This tree will represent two complete MAX-MIN pairs of moves. The top level of the tree is MAX; the next level (3 nodes) is MIN; the third level (9 nodes) is MAX; the fourth (27) is MIN; and the fifth (81 nodes) are the leaves of the tree, labeled with the following numbers, grouped in sets of 27, and reading from left to right: 837 259 538 257 948 632 495 172 246 147 842 578 246 956 102 453 9 27 317 956 401 345 123 734 432 827 193 273 As usual, MAX is trying to achieve the highest number; MIN the lowest. (a) What is the overall value of this tree to MAX? (b) How many of these leaves 81 leaves actually have to be evaluated by an alpha-beta game search algorithm assuming that possible moves are examined from left to right? (c) How many leaves have to be evaluated by alpha-beta assuming that moves are examined from right to left? (d) Suppose the root player is MIN. (That is, the levels of the tree are now MIN, MAX, MIN, and MAX.) Now how many of the 81 leaves have to be evaluated by an alpha-beta searcher if moves are examined from left to right?Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct queueNode
{
int cust_n;
int serv_t;
int arr_t;
struct queueNode *nextPtr;
};
typedef struct queueNode customer;
typedef customer *customerPtr;
void printQueue( customerPtr );
int isEmpty( customerPtr );
void dequeue( customerPtr *, customerPtr * );
void enqueue( customerPtr *, customerPtr *, int ,int ,int );
int main()
{
int i; int t_time = 0;
int t_arrival = 0;
int t_depart = -1;
int customer_n = 0;
int serv_time = 0;
int MAX_SERV_TIME = serv_time;
int tot_wait_t = 0;
customerPtr headptr = NULL,tailptr = NULL;
srand((unsigned int)time(NULL));
while(t_time != 10)
{
printf("TIME = %d,MAX_SERV_TIME = %d,TOT WAIT TIME = %d ",t_time,MAX_SERV_TIME,tot_wait_t);
if(t_time == t_depart && !isEmpty(headptr))
{
printf("customer %d ON ",headptr->cust_n);
serv_time = headptr->serv_t;
service time tot_wait_t += (t_time - headptr->arr_t);
dequeue(&headptr,&tailptr);
if(!isEmpty(headptr)) t_depart = serv_time + t_time;
}
if(t_time == t_arrival)
{
serv_time = rand()%4 + 1;
MAX_SERV_TIME = (serv_time>MAX_SERV_TIME?serv_time:MAX_SERV_TIME);
if(isEmpty(headptr)) t_depart = t_time + serv_time;
enqueue(&headptr,&tailptr,customer_n,serv_time,t_arrival);
t_arrival += rand()%4 + 1;
printf("customer %d joins at %d,serv_time %d,new_cust %d ",tailptr->cust_n,tailptr->arr_t,tailptr->serv_t,t_arrival);
}
printQueue(headptr);
getchar();
t_time++;
}
customer_n = (tailptr->cust_n - headptr->cust_n)+ 1;
printf("average wait time = %d,max service time = %d,tot custs unserved %d ",tot_wait_t/customer_n,MAX_SERV_TIME,customer_n);
for(i = 0;i<customer_n;i++)
{
printQueue(headptr);
getchar();
dequeue(&headptr,&tailptr); } //printQueue(headptr); return 0;
}
void enqueue( customerPtr *headPtr, customerPtr *tailPtr,int cust_n,int serv_t,int arr_t)
{
customerPtr newPtr; newPtr = malloc( sizeof( customer ) );
if ( newPtr != NULL )
{
newPtr->cust_n = cust_n;
newPtr->serv_t = serv_t;
newPtr->arr_t = arr_t;
newPtr->nextPtr = NULL;
if ( isEmpty( *headPtr ) ) *headPtr = newPtr;
else ( *tailPtr )->nextPtr = newPtr;
*tailPtr = newPtr;
}
else
printf("No memory available. ");
}
void dequeue( customerPtr *headPtr, customerPtr *tailPtr )
{
customerPtr tempPtr;
tempPtr = *headPtr;
*headPtr = ( *headPtr )->nextPtr;
if ( *headPtr == NULL ) *tailPtr = NULL;
free( tempPtr );
}
int isEmpty( customerPtr headPtr )
{
return headPtr == NULL;
}
void printQueue( customerPtr currentPtr )
{
if ( currentPtr == NULL )
printf( "Queue is empty. " );
else
{
printf( "The queue is: " );
while ( currentPtr != NULL )
{
printf( "%d <-- ", currentPtr->cust_n );
currentPtr = currentPtr->nextPtr;
}
printf( "NULL " );
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.