Home Java A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)

A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)

by admin

A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
This is the 4th article in a series on model-driven development.In the previous articles, we were introduced to OCL and metamodels. , Eclipse Modeling Framework and Sirius Today we will learn how to describe metamodels in textual notation (rather than diagrams as before) and get acquainted with the tabular representation of models in Sirius. We will do this with the example of the midlife crisis and the hierarchy analysis method. Perhaps this will come in handy when developing AI in games, in decision making, or in your work.

Introduction

Actually, I was planning an article about DSL development and model conversion. But my plans were suddenly interrupted by thoughts about the meaning of life, about whether I was doing the right thing at all.
The most obvious thing a model-driven development specialist can do with this is

  • Select the method that will produce the answers of interest (Section 1)
  • Create a metamodel for the method (Section 2)
  • Create a model development tool according to the metamodel (Section 3)
  • Create a model (section 4)
  • Profit

That’s exactly what we’re going to do.

Note
If you are interested in the method of analyzing hierarchies, but don’t want to understand metamodels, etc., then Excel priority calculator available here

A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)

1 Hierarchy analysis method

I was interested in the following questions :

  • What am I interested in doing?
  • Do I spend enough time doing interesting things?
  • What can I change in my life for the better?
  • Won’t these changes make things worse?

When I was in college, we used to use hierarchy analysis method The essence of the method is as follows.

  1. You determine
    • target,
    • The criteria for achieving the goal and
    • possible alternatives.
    • Evaluate the significance of the criteria.
    • Evaluate the alternatives for each of the criteria.
    • You calculate the priorities of the alternatives.
    • Making a decision.

    This method is described in more detail in Thomas Saaty’s book "Decision Making. Hierarchy Analysis Method" (it can be easily googled). By the way, it has many examples from psychology to world economy.

    1.1 Building a hierarchy

    So, in the simplest case, the hierarchy should contain a goal, criteria, and alternatives.
    To summarize all my questions, basically, I’m wondering if I should change jobs. So the goal is : choose a job
    When choosing a job, I am interested in

    • how much money I will make,
    • by how much interesting I’m going to be doing this,
    • Will I have time for a life,
    • quarry prospects,
    • Will I be able to be on the nature Or will I see the sun and the trees once a year,
    • How close to me culture coworkers, neighbors, and the rest of the people.

    The following alternatives are possible :

    • do not change anything,
    • To move to Moscow,
    • To move abroad,
    • Do freelance work or do some entrepreneurial work.

    The following hierarchy is constructed according to the method of hierarchy analysis :
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)

    1.2 Evaluation of criteria

    Different people may have roughly the same criteria when making decisions. However, their importance can vary greatly. Some people work more for the money, some for the interest, some people just like to communicate with their colleagues, etc.
    According to their priorities, one person will not hesitate to choose a more monetary job, while another will choose a more interesting one. There is no job that suits everyone by all criteria.
    Probably when making decisions, most people explicitly or implicitly rank the criteria from the most significant to the least significant. They discard the latter and compare possible alternatives on the former. For each possible job they put a label:here, this job is more money, but not interesting, and this interesting and the team there is good, but dubious career prospects, etc.
    If you can’t make a choice right away, you start overestimating the criteria: maybe the interest is not that important yet, and you can spend an extra two hours in a traffic jam, but the salary is higher, so I’ll pay the mortgage and do something interesting.
    This kind of reasoning can go on for a long, painful time with no guarantee that in the end the best decision will actually be made.
    The method of hierarchy analysis offers a formal algorithm for making such decisions: all the criteria are compared to each other in pairs on a scale from 1 to 9.
    For example, what is more important to me: interest or money? Interest is more important, but not very much. If the maximum score is 9 to 1, then for myself I rate my priorities as 5 to 1.
    Or, for example, what is more important: money or having time for life, hobbies? Am I ready to work on weekends for extra money or to stand for two hours in traffic jams? For myself I estimate the importance of these criteria as 1 to 7.
    The result is a table like this :
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
    It is obvious that there will always be ones along the diagonal. It is also obvious that all scores will be inversely symmetric with respect to the main diagonal. For example, if I estimate the importance of interest-money as 5 to 1, then the importance of money-interest will be 1 to 5. Sometimes such matrices are called inverse-symmetric.
    In the general case, if we compare N criteria, we need to make (N*(N-1))/2 comparisons. It would seem that things have only gotten more complicated. If originally there were 6 criteria, now there is a whole matrix of some numbers. To get back to the criteria again, let’s calculate the eigenvector of the matrix. The elements of this vector will be the relative importance of each criterion.
    Thomas Saaty’s book suggests several simplified methods for calculating an eigenvector in mind or on paper. We will use the more precise iterative algorithm :

    N = number of criteriam = score matrix of dimension NxNeigenvector = vector of size N, filled with values 1/NRepeat until eigenvalue begins to converge to a certain valueor until the maximum allowed number of iterationsx = m * eigenvectoreigenvalue = sum(x)eigenvector = x / eigenvalue

    We end up with the following vector :

    [ 0, 0592; 0, 2323; 0, 3846; 0, 0555; 0, 1220; 0, 1462 ]

    The most significant criterion is time (0.3846), the least significant is career (0.0555).
    In pairwise comparisons, some evaluations may turn out to be inconsistent. For example, for me, interest is more important than money, and money is more important than career. Obviously, interest should be significantly more important than career. In this table, it is. But if the score for "interest-career" were lower or even the opposite, then my scores would be inconsistent with each other.
    The eigenvalue of the comparison matrix will help you estimate the measure of this inconsistency. It is equal to 6.7048.
    Obviously, the eigenvalue is proportional to the number of criteria. In order to make the evaluation of consistency not depend on the number of criteria, the so-called consistency index = (eigenvalue – N) / (N – 1) is calculated.
    Finally, in order to make the estimation completely objective it is necessary to divide this index by the average consistency index for random matrices. If the obtained value (consistency ratio) is less than 0.1000, then the pairwise comparisons can be considered more or less consistent. In our example it is 0.1137, which means that the calculated priorities can be more or less trusted.

    1.3 Evaluation of alternatives

    Now we need to compare all the alternatives for each of the criteria.
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
    For example, if I move to Moscow, I will gain substantially in salary. But the job will probably be less interesting and there will be less time to live. Or if I move abroad, I will have to give up my language and adjust to other people’s cultural values.
    For each criterion the eigenvector and consistency ratio are calculated.
    The resulting eigenvectors are written in the columns :
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
    The consistency relationships for each criterion are written in the following vector :

    [ 0, 0337; 0, 0211; 0, 1012; 0, 1399; 0, 1270; 0, 9507 ]

    Most of the values are less than or slightly above 0.1000. However, for the "culture" criterion, the consistency ratio turned out to be very high. This is due to the fact that I misplaced some of the scores. I wanted to put a 7 for "do nothing to change – move abroad, " because living in your hometown is much more comfortable. But by mistake I gave it a 1/7.

    1.4 Prioritizing alternatives

    So, we have evaluated the criteria, labeled each alternative: which option is more money, which is more interesting, etc. Now we need to evaluate the alternatives for all the criteria in total. To do this, just multiply the matrix
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
    vector

    [ 0, 0592; 0, 2323; 0, 3846; 0, 0555; 0, 1220; 0, 1462 ]

    We end up with the following vector :

    [ 0, 3184; 0, 1227; 0, 2049; 0, 3540 ]

    This is the significance of the alternatives with respect to achieving the goal.

    1.5 Decision making

    Now show all the calculated values in the following figure :
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
    The ratio of the consistency of the estimates is given in parentheses.
    The thickness of the lines is proportional to priorities.A current job is the most interesting and promising in terms of career.Freelancing would allow more time outdoors and more time to spend on life. More monetary work in Moscow and abroad.
    You can see that Moscow is totally off. Abroad is a little better, but also not good. Nothing to change and freelancing is about the same.

    2 Creating a meta model

    Now let’s describe how all this is drawn and counted.
    First, we need to describe the metamodel : the types of entities that are used in the hierarchy analysis method. Moreover, unlike. previous article we will not draw the metamodel as a diagram, but describe it in Xcore textual notation.
    As before you will need Eclipse Modeling Tools Install Xcore and Sirius.
    You can either get a ready-made project , or you can do it yourself. If you do it yourself, create an Xcore project. In the model folder create the file ahp.xcore with the following contents :

    @Ecore(nsURI="http://www.example.org/ahp")@GenModel(modelName="AHP", prefix="AHP", editDirectory="/xctest.edit/src-gen", editorDirectory="/xctest.editor/src-gen", testsDirectory="/xctest.tests/src-gen")package ahpclass Hierarchy{contains Goal[1] goalcontains Criterion[+] criteriacontains Alternative[2..*] alternatives}interface Named{String[1] name}class Goal extends Named { }class Criterion extends Named { }class Alternative extends Named { }

    The meaning should be intuitive. We have described a hierarchy that contains one goal, at least one criterion, two or more alternatives. All three entities have a name.
    After saving the file, the Java API for working with hierarchies in the src-gen folder will be automatically generated. And also 3 additional projects will be created. We already did something similar in article about EMF Only there were two models (ecore and genmodel) and we ran the code generation manually. Xcore does it automatically.
    I think there is no point in describing the whole metamodel in the article, you can look it up on your own
    Let’s focus only on the most interesting things. Xcore, unlike Ecore, allows you to describe not only the structure of the model, but also some logic in a Java-like language. For example, let’s describe the data type for storing evaluations. Positive estimates will be stored as positive integers. And we will store inverse estimates of the form 1/n as -n. We could store estimates as strings or as real numbers, but that’s probably not a good idea.
    In this case, we need two functions to convert grades from or to string representation. On Xcore, this would look like this :

    type Weight wraps intcreate{if (it.matches("\\d+")) {Integer.parseInt(it)}else if (it.matches("1\\s*/\\s*\\d+")) {val result = Integer.parseInt(it.replaceFirst("1\\s*/\\s*", ""))if (result <= 1) 1 else -result}else {throw new NumberFormatException("The weight must be either n or 1/n")}}convert{if (it > = 1) {it.toString}else if (it > = -1) {"1"}else {"1/" + (-it).toString}}

    Xcore allows you to describe relatively complex logic as well.
    Here, for example, is the operation of calculating priorities in a hierarchy.

    class Hierarchy{op void updatePriorities(){priorities.clearinconsistencies.clearval mat = new JudgmentMatrix<Criterion> (criteria)val criteriaJudgments = judgments.filter(typeof(CriterionJudgment)).filter(cj | cj.goal == goal)for (judgment : criteriaJudgments) {mat.set(judgment.first, judgment.second, judgment.weight)}for (criterion : criteria) {val GoalCriterionPriority priority = AHPFactory.eINSTANCE.createGoalCriterionPrioritypriority.goal = goalpriority.criterion = criterionpriority.value = mat.findEigenvectorElement(criterion)priorities.add(priority)}val goalInconsistency = AHPFactory.eINSTANCE.createGoalInconsistencygoalInconsistency.goal = goalgoalInconsistency.value = mat.inconsistencyinconsistencies.add(goalInconsistency)val mat2 = new Matrix(alternatives.size, criteria.size)criteria.forEach[criterion, j|val mat3 = new JudgmentMatrix<Alternative> (alternatives)val alternativeJudgments = judgments.filter(typeof(AlternativeJudgment)).filter(aj | aj.criterion == criterion)for (judgment : alternativeJudgments) {mat3.set(judgment.first, judgment.second, judgment.weight)}val criterionInconsistency = AHPFactory.eINSTANCE.createCriterionInconsistencycriterionInconsistency.criterion = criterioncriterionInconsistency.value = mat3.inconsistencyinconsistencies.add(criterionInconsistency)alternatives.forEach[alternative, i|val CriterionAlternativePriority priority = AHPFactory.eINSTANCE.createCriterionAlternativePrioritypriority.criterion = criterionpriority.alternative = alternativepriority.value = mat3.findEigenvectorElement(alternative)priorities.add(priority)mat2.set(i, j, priority.value)]]val mat4 = mat2.multiply(mat.eigenvector)alternatives.forEach[alternative, i|val GoalAlternativePriority priority = AHPFactory.eINSTANCE.createGoalAlternativePrioritypriority.goal = goalpriority.alternative = alternativepriority.value = mat4.get(i)priorities.add(priority)]}}

    Finally, for the Xcore model (as for the Ecore model) you can create a class diagram.
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
    This is what the metamodel for the hierarchy analysis method looks like. This is a simplified version as much as possible. And in the general case, a hierarchy can contain more than three levels (for example, criteria can have subcriteria). The matrices of connections between levels may be sparse. More than one expert can give a score, not just one.

    3 Developing a modeling tool

    The metamodel is ready, now we need a hierarchy and matrix editor. There’s probably no point in describing in detail how it’s all done. If you’re interested, you can read previous article about Sirius and see the finished project
    This is what the chart and table editor specification looks like :
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
    This is what the resulting editor looks like :
    A Job Search Guide for the MDA Specialist (and a bit about the Hierarchy Analysis Method,Xcore, and Sirius)
    It wasn’t possible to describe the hierarchy editor completely declaratively, I had to write extensions in Java. I think we should elaborate on this a bit more. Sirius has at least two kinds of extensions: service and action.
    With services, you can add some additional operations to classes from the metamodel. For example, the following two operations respectively format the priority and calculate the thickness of links between criteria and alternatives.

    public class Service {public String toString(Priority priority) {return String.format("%.4f", priority.getValue());}public int getEdgeWidth(Alternative alternative, EdgeTarget targetView) {DSemanticDecorator targetNode = (DSemanticDecorator)targetView;Criterion criterion = (Criterion)targetNode.getTarget();Priority priority = alternative.getPriority(criterion);return (int) (priority.getValue() * 7);}}

    What is convenient is that you can use these operations directly in AQL expressions. However, you cannot use them to change the model.
    You need to use Java actions to change the model. Actions, unlike services, can no longer be called in AQL expressions. They can be triggered, for example, via a context menu or by pressing a button. Actions can be rolled back using the Undo command.
    Example of an action that recalculates priorities in a hierarchy.

    package ahp.design;import java.util.Collection;import java.util.Iterator;import java.util.Map;import org.eclipse.emf.ecore.EObject;import org.eclipse.emf.transaction.RecordingCommand;import org.eclipse.emf.transaction.TransactionalEditingDomain;import org.eclipse.sirius.business.api.action.AbstractExternalJavaAction;import org.eclipse.sirius.business.api.session.Session;import org.eclipse.sirius.business.api.session.SessionManager;import org.eclipse.sirius.diagram.DSemanticDiagram;import ahp.Hierarchy;public class UpdatePrioritiesAction extends AbstractExternalJavaAction {public UpdatePrioritiesAction() {}@Overridepublic boolean canExecute(Collection<? extends EObject> arg0) {return true;}@Overridepublic void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {Iterator<? extends EObject> iter = selections.iterator();if (!iter.hasNext()) {System.out.println("Selections is empty");return;}EObject obj = selections.iterator().next();if (!(obj instanceof DSemanticDiagram)) {System.out.println("DSemanticDiagram is expected");}DSemanticDiagram diagram = (DSemanticDiagram)obj;EObject target = diagram.getTarget();if (!(target instanceof Hierarchy)) {System.out.println("Hierarchy is expected");}Hierarchy hierarchy = (Hierarchy)target;Session session = SessionManager.INSTANCE.getSession(target);TransactionalEditingDomain ted = session.getTransactionalEditingDomain();RecordingCommand cmd = new RecordingCommand(ted) {@Overrideprotected void doExecute() {hierarchy.updatePriorities();}};ted.getCommandStack().execute(cmd);}}

    4 Creating a model

    Well, actually, I already created my model and showed it above. Try taking this one project And build your hierarchy.

    Profit

    After reading this article, you should

    • to get a general idea of the method of hierarchy analysis,
    • Learn to describe metamodels in the Xcore language,
    • Learn how to create summary tables using Sirius,
    • Learn to write extensions for Sirius in Java.

    You may also like