首页 > 编程语言 >CSCI561 算法解析

CSCI561 算法解析

时间:2023-04-09 15:46:07浏览次数:45  
标签:txt knowledge should will 算法 CSCI561 input 解析 your

CSCI561
CSCI561 First Order Logic Resolutio
Guidelines
This is a programming assignment. You will be provided with sample inputs and outputs (see below). Please understand that the goal of the samples is to check that you can correctly parse the problem definition and generate a correctly formatted output. The samples are very simple and you should not assume that if your program works on the samples it will work on all test cases. There will be more complex test cases and it is your task to make sure that your program will work correctly on any valid input. You are encouraged to try your own test cases to check how your program would behave in some complex special case that you might think of. Since each homework is checked via an automated A.I. script, your output should match the example format exactly. Failure to do so will most certainly cost some points. The output format is simple and examples are provided. You should upload and test your code on vocareum.com, and you will submit it there. You may use any of the programming languages and versions thereof provided by vocareum.com.

Grading
Your code will be tested as follows: Your program should take no command-line arguments. It should read a text file called “input.txt” in the current directory that contains a problem definition. It should write a file “output.txt” with your solution. Format for files input.txt and output.txt is specified below. End-of-line convention is Unix (since vocareum is a Unix system).

The grading A.I. script will, 50 times:

Create an input.txt file, delete any old output.txt file.
Run your code.
Compare output.txt created by your program with the correct one.
If your outputs for all 50 test cases are correct, you get 100 points.
If one or more test case fails, you lose 2 points for each failed test case. (Note that one test case involves only one query in this HW).
Note that if your code does not compile, or somehow fails to load and parse input.txt, or writes an incorrectly formatted output.txt, or no output.txt at all, or OuTpUt.TxT, you will get zero points. Please test your program with the provided sample files to avoid this. You can submit code as many times as you wish on vocareum, and the last submitted version will be used for grading.

Project Description
Today, your dad is opening his dream restaurant after working at a desk job for the last few decades. He has always been passionate about food, but there is one other thing he loves more: Money. Trying to cut some expenses, he came up with an amazing idea and convinced you to design an automated system to manage the restaurant for him. This automated system will take over most of the dining room duties: It will decide whether there is a table to seat the incoming customers, take their orders according to restaurant policies and current stock, and bring them their check once they are done eating. Using this system, your dad can instead spend most of his budget on an amazing chef and fresh ingredients. You are hoping the customers would love this concept and make the restaurant very popular!

You sit down with your dad to develop a beta version of the system. Having just taken CSCI561 last semester, you decide to implement it using first-order logic resolution. Current restaurant status, policies, ingredient stock and customer status will all be encoded as first order logic sentences in the knowledge base. The knowledge given to you contains sentences with the following defined operators:

The program takes a query and provides a logical conclusion to whether it is true or not.

Format for input.txt
<QUERY>
<K = NUMBER OF GIVEN SENTENCES IN THE KNOWLEDGE BASE>
<SENTENCE 1>
...
<SENTENCE K>
The first line contains a query as one logic sentence (further detailed below). The line after contains an integer K specifying the number of sentences given for the knowledge base. The remaining K lines contain the sentences for the knowledge base, one sentence per line.

Query format
The query will be a single literal of the form Predicate(Constant_Arguments) or
~Predicate(Constant_Arguments) and will not contain any variables. Each predicate will have between 1 and 25 constant arguments. Two or more arguments will be separated by commas.

KB input format
Each sentence to be inserted into the knowledge base is written in FOL using operators &, |, =>, and ~, with the following conventions:

& denotes the conjunction operator.
| denotes the disjunction operator.
=> denotes the implication operator.
~ denotes the negation operator.
No other operators besides &, |, =>, and ~ are used in the input to the knowledge base.
There will be NO parentheses in the input to the KB except to mark predicate arguments. For example: Pred(x,y) is allowed, but A & (B | C) is not.
Variables are denoted by a single lowercase letter.
All predicates (such as Order(x,y) which means person x orders food item y) and constants (such as Broccoli) are case sensitive alphanumeric strings that begin with an uppercase letter.
Thus, when parsing words in the input to the KB, use the following conventions:
9.1. Single lowercase letter: variable. E.g.: x, y, z
9.2. First letter is uppercase and opening parenthesis follows the current word: predicate. E.g.: Order(x,y), Pred52(z)
9.3. Otherwise: constant. E.g.: Harry, Pizza123
Each predicate takes at least one argument (so, all predicate names are always followed by an opening parenthesis). Predicates will take at most 25 arguments. A given predicate name will not appear with different number of arguments.
Predicate arguments will only be variables or constants (no nested predicates).
There will be at most 100 sentences in the knowledge base.
See the sample input below for spacing patterns.
You can assume that the input format is exactly as it is described.
There will be no syntax errors in the given input.
The KB will be true (i.e., will not contain contradictions).
Note that the format we just specified is broader than both Horn form and CNF. Thus, you should first convert the given input sentences into CNF and then insert the converted sentences into your CNF KB for resolution.
Format for output.txt
Your program should determine whether the query can be inferred from the knowledge base or not, and write a single line to output.txt:

<ANSWER>
Each answer should be either TRUE if you can prove that the corresponding query sentence is true given the knowledge base, or FALSE if you cannot. This is a so-called “closed-world assumption” (things that cannot be proven from the KB are considered false).

Notes and hints
Please name your program “homework.xxx” where ‘xxx’ is the extension for the programming language you choose. (“py” for python3, “cpp” for C++11, and “java” for
Java).
If you decide that the given statement can be inferred from the knowledge base, every variable in each sentence used in the proving process should be unified with a Constant (i.e., unify variables to constants before you trigger a step of resolution).
All variables are assumed to be universally quantified. There is no existential quantifier in this homework. There is no need for Skolem functions or Skolem constants.
Operator priorities apply (e.g., negation has higher priority than conjunction).
The knowledge base is consistent.
If you run into a loop and there is no alternative path you can try, report FALSE. For example, if you have two rules (1) ~A(x) | B(x) and (2) ~B(x) | A(x) and wanting to prove A(Teddy). In this case your program should report FALSE.
Note that the input to the KB is not in Horn form. So you indeed must use resolution and cannot use generalized Modus Ponens.
Example 1
WX:codehelp mailto: [email protected]

标签:txt,knowledge,should,will,算法,CSCI561,input,解析,your
From: https://www.cnblogs.com/oknice/p/17300393.html

相关文章

  • 数组的算法
    数值型数组特征值统计这里特征值涉及到:平均值,最大值,最小值,总和等求最大值:将数组第一个元素假设为最大值intmax=arr[0];再然后用写一个判断语句如果数组第一个元素小于当前比较的元素就把当前比较的元素赋值给maxif(max<arr[i]){max=arr[i]}求最小值:定义一个变量这个数大......
  • .NET 配置文件禁止解析特定扩展名
    .NET禁止解析特定文件扩展名,使用web.config配置handler节点,所有的HTTP请求均被系统System.Web.HttpForbiddenHandler拦截,例如限制当前web目录不允许解析aspx扩展名<system.webServer><handlers> <addname="test1"path="*.aspx"verb="*"type="System......
  • 【算法题】831. 隐藏个人信息
    题目:给你一条个人信息字符串s,可能表示一个邮箱地址,也可能表示一串电话号码。返回按如下规则隐藏个人信息后的结果:电子邮件地址:一个电子邮件地址由以下部分组成:一个名字,由大小写英文字母组成,后面跟着一个‘@’字符,后面跟着一个域名,由大小写英文字母和一个位于中间的......
  • Lasso回归_ElasticNet回归_PolynomialFeatures算法介绍---人工智能工作笔记0032
    然后我们再来看这个ridge回归,可以看到这里的这个岭回归,可以看到他的损失函数,其实就是添加了一个使用L2的正则化的,惩罚项对吧,目的是为了增强,损失函数的泛化能力,这里的alpha,实际上作用是为了,调整,这个损失函数的,正确率多一点还是泛化能力强一点. 可以看到他的使用函数的方......
  • 分布式存储技术(下):宽表存储与全文搜索引擎的架构原理、特性、优缺点解析
    对于写密集型应用,每天写入量巨大,数据增长量无法预估,且对性能和可靠性要求非常高,普通关系型数据库无法满足其需求。对于全文搜索和数据分析这类对查询性能要求极高的场景也是如此。为了进一步满足上面两类场景的需求,有了宽表存储和搜索引擎技术,本文将对他们的架构、原理缺点做介绍。......
  • java-信息安全(二十)国密算法 SM1,SM2,SM3,SM4
    一、概述国密即国家密码局认定的国产密码算法。主要有SM1,SM2,SM3,SM4。密钥长度和分组长度均为128位。目前主要使用公开的SM2、SM3、SM4三类算法,分别是非对称算法、哈希算法和对称算法。SM1 为对称加密。其加密强度与AES相当。该算法不公开,调用该算法时,需要通过加密芯片的接口进......
  • 快速幂算法
    快速幂算法设计一个算法计算\(x^n\)的值。根据定义最常见也最能瞬间想到的是如下的算法://递归写法publicintpow1(intx,intn){if(n==0)return1;if(n==1)returnx;returnx*pow1(x,n-1);}//循环写法publicintpow2(intx,intn){inty......
  • 算法学习之冒泡排序【C语言】
    冒泡排序排序规则冒泡排序的规则是相邻的两个数字依次比较,如果前面的数字比后面的数字大,则交换它们的位置,否则保持不变,直到遍历完所有的数字。这个过程会不断地进行,直到所有的数字都按照从小到大的顺序排列好。双层循环在冒泡排序的算法中,需要使用两层循环来实现排序功能。for(int......
  • 【Python】python中的argparse包在解析bool型参数时的细节问题
    1.参数定义定义了如下三个参数,其中use_entity_type和use_entity_id是bool参数。这两个bool型参数的默认值都是True。2.命令行传参这里是vscode中的launch.json文件中的参数定义,想把下面的两个参数修改成False。3.运行过程运行代码,但是发现经过parser.parse_args()之后,参数u......
  • 算法-递归三(树形结构)
    publicclassSolution{publicIList<IList<int>>Permute(int[]nums){varrtItem=newList<int>();varvisited=newDictionary<int,bool>();IList<IList<int>>rt=newList<IList<int&......