对“问题”建模
摘自:《 The Algorithm Design Manual 》by Steve S. Skiena
刘建文略译( http://blog.csdn.net/keminlau)
Modeling the Problem
Modeling is the art of formulating your application in terms of precisely described, well-understood problems. Proper modeling is the key to applying algorithmic design techniques to any real-world problem. Indeed, proper modeling can eliminate the need to design or even implement algorithms by relating your application to what has been done before. Proper modeling is the key to effectively using the problem catalog in Part II of this book.
为问题或任务建造模型是一种艺术,问题的模型是问题的一种描述精确和易理解的形式。适当的建造模型是应用算法设计技术解决任何实际问题的关键,因为你可以复用过曾经使用过的建模经验(KEMIN:都还没有给“问题建模”定位就谈经验是不是有点问题?)。适当建模是有效使用本书第二部分的问题清单(problem catalog)的关键。
Real-world applications involve real-world objects. You might be working on a system to route traffic in a network, to find the best way to schedule classrooms in a university, or to search for patterns in a corporate database. Most algorithms, however, are designed to work on rigorously defined abstract structures such as permutations, graphs, and sets. After all, if you can't define what you want to do, you can't hope to compute it. You must first describe your problem abstractly, in terms of fundamental structures and properties.
真实世界处理是真实的对象。你可能处理诸如这样的问题:设计一个网络通信的路由系统、为大学找出最佳的课程表、或者查找公司数据的某条记录。但是,大部分算法被设计成处理有严格定义的抽象结构,如列表、图和集合。问题来了,你无法定义你想要做什么,那么你也就没法知道如何去处理(计算)它。因此,你必须先抽象地描述你的问题,以一些基本的结构和属性。
Whatever your application is, odds are very good that others before you have stumbled upon the same algorithmic problem, perhaps in substantially different contexts. Therefore, to find out what is known about your particular ``widget optimization problem,'' you can't hope to look in a book under widget. You have to formulate widget optimization in terms of computing properties of abstract structures such as:
l Permutations, which are arrangements, or orderings, of items. For example,{4,2,3,1} and {1,2,3,4} are two distinct permutations of the same set of four integers. Permutations are likely the object in question whenever your problem seeks an ``arrangement,'' ``tour,'' ``ordering,'', or ``sequence.''
排列,就是元素的安排或排序。问题如找出…………用到的都是排列
l Subsets, which represent selections from a set of items. For example, {1,3,4} and {2} are two distinct subsets of the first four integers. Order does not matter in subsets the way it does with permutations, so the subsets {1,3,4} and {3,4,1} would be considered identical. Subsets are likely the object in question whenever your problem seeks a ``cluster,'' ``collection,'' ``committee,'' ``group,'' ``packaging,'' or ``selection.''
子集(组合),就是从一预定的集合中选择一些元素。子集(组合)内的元素的顺序是无关的。
Trees, which represent hierarchical relationships between items. Figure (a) illustrates a portion of the family tree of the Skiena clan. Trees are likely the object in question whenever your problem seeks a ``hierarchy,'' ``dominance relationship,'' ``ancestor/decendant relationship,'' or ``taxonomy.''
树
l Graphs, which represent relationships between arbitrary pairs of objects. Figure (b) models a network of roads as a graph, where the vertices are cities and the edges are roads connecting pairs of cities. Graphs are likely the object in question whenever you seek a ``network,'' ``circuit,'' ``web,'' or ``relationship.''
图
l Points, which represent locations in some geometric space. For example, the locations of McDonald's restaurants can be described by points on a map/plane. Points are likely the object in question whenever your problems work on ``sites,'' ``positions,'' ``data records,'' or ``locations.''
点
l Polygons, which represent regions in some geometric space. For example, the borders of a country can be described by a polygon on a map/plane. Polygons and polyhedra are likely the object in question whenever you are working on ``shapes,'' ``regions,'' ``configurations,'' or ``boundaries.''
多边形
l Strings, which represent sequences of characters or patterns. For example, the names of students in a class can be represented by strings. Strings are likely the object in question whenever you are dealing with ``text,'' ``characters,'' ``patterns,'' or ``labels.''
字串
These fundamental structures all have associated problems and properties, which are presented in the catalog of Part II. Familiarity with all of these problems is important, because they provide the language we use to model applications. To become fluent流利的; 流畅的 in this vocabulary, browse through the catalog and study the input and output pictures for each problem. Understanding all or most of these problems, even at a cartoon/definition level, will enable you to know where to look later when the problem arises in your application.
这些基本结构全都有相对应的问题类型和属性,这些内容在本书第二部分的有一个清单(problem catalog)。熟悉所有这些问题类型是重要的,因为它们为你提供了问题建模的语言。要熟练掌握建模词汇,可浏览那问题清单并逐一研究每个问题的输入和输出图。理解了所有或大部分这些问题类型(即使是很初步的了解)可让你在遇到实际问题时不致于迷失方向而手足无措。
Examples of successful application modeling will be presented in the war stories spaced throughout this book. However, some words of caution are in order. The act of modeling reduces your application to one of a small number of existing problems and structures. Such a process is inherently constraining, and certain details might not fit easily into the given model. Also, certain problems can be modeled in several different ways, some much better than others.
本书介绍一个成功的问题建模例子--战争故事。建模的时候有些东西是要注意的……FIXME……这个过程是固有的约束,一些细节并不能很好对上指定的模型。还有,一个特定的问题可有多种建模方式,其中有优劣之分。
Modeling is only the first step in designing an algorithm for a problem. Be alert for how the details of your applications differ from a candidate model. But don't be too quick to say that your problem is unique and special. Temporarily ignoring details that don't fit can free the mind to ask whether they were fundamental in the first place.
建模只是为问题设计算法的第一步。注意比较你的问题的细节在各个候选模型间区别。不必急于下定论说你的问题很特殊的,暂时忽略一些套不上模型的细节可解开的思维定势,细心想想它们在本质层面是否一样的。
参考
Design and Analysis of Algorithms
Data Structures and Algorithms
Alfred V. Aho, Bell Laboratories, Murray Hill, New Jersey
John E. Hopcroft, Cornell University, Ithaca, New York
Jeffrey D. Ullman, Stanford University, Stanford, California
There are many steps involved in writing a computer program to solve a given problem. The steps go from problem formulation and specification, to design of the solution, to implementation, testing and documentation, and finally to evaluation of the solution. This chapter outlines our approach to these steps. Subsequent chapters discuss the algorithms and data structures that are the building blocks of most computer programs.
编写计算机程序解决一个问题是一个复杂的过程。这个过程包括问题分析和建模、设计解决方案、代码实现、测试和编写文档,最后对解决方案进行评估。
1.1 From Problems to Programs
Half the battle is knowing what problem to solve. When initially approached, most problems have no simple, precise specification. In fact, certain problems, such as creating a "gourmet" recipe or preserving world peace, may be impossible to formulate in terms that admit of a computer solution. Even if we suspect our problem can be solved on a computer, there is usually considerable latitude in several problem parameters. Often it is only by experimentation that reasonable values for these parameters can be found.
清晰知道待解决的问题是成功的一半。大多数问题一开始并没有一个简单的、精确的描述(规格specification)。而且实际上有一些问题,比如创建一个美食食谱之类的现实问题,超出了计算机可处理的范围。即便是我们认为计算机应该可以处理的问题,也常常要限制问题的一些参数。这也常常需要经验才能知道……FIXME
If certain aspects of a problem can be expressed in terms of a formal model, it is usually beneficial to do so, for once a problem is formalized, we can look for solutions in terms of a precise model and determine whether a program already exists to solve that problem. Even if there is no existing program, at least we can discover what is known about this model and use the properties of the model to help construct a good solution.
为问题建造形式模型对解决问题是很有益处的。第一可以套用已有问题解决方案;第二,即使没有现成的例子,形式模型也使问题有迹可循,有助于找到更好的问题的解决方案。
Almost any branch of mathematics or science can be called into service to help model some problem domain. Problems essentially numerical in nature can be modeled by such common mathematical concepts as simultaneous linear equations (e.g., finding currents in electrical circuits, or finding stresses in frames made of connected beams) or differential equations (e.g., predicting population growth or the rate at which chemicals will react). Symbol and text processing problems can be modeled by character strings and formal grammars. Problems of this nature include compilation (the translation of programs written in a programming language into machine language) and information retrieval tasks such as recognizing particular words in lists of titles owned by a library.
几乎任何一个数学或科学的分支都可以被认为是为某一个问题领域建造模型。数值问题可以被建模成一些数学概念,像联立线性方程(simultaneous linear equations)或微分方程(differential equations),联立线性方程解决如求电路电流量,而微分方程预测人口增长等问题。