Hungarian Algorithm - PHP version - php

I am trying to implement the job assignment Hungarian algorithm. http://en.wikipedia.org/wiki/Hungarian_algorithm#The_algorithm_in_terms_of_bipartite_graphs
[I think I understand the algorithm, but am not able to appreciate why is it O(n^3). But that is just a curiosity.]
What I am looking for is a PHP implementation of Hungarian algorithm. The Wikipedia link does have a link to implementations, but I have not found PHP version yet.

Most likely you want to look at this article Floyd-Warshall and the all-pairs-shortest-path problem. Unfortunately it is in C but it can help you with the implementation in php ( http://wilanw.blogspot.com/2010/01/floyd-warshall-all-pairs-shortest-path.html ).

This code in Python should be fairly easy to translate to PHP
http://pastebin.com/tn6v0HDr

Related

Generating php from delphi - has anyone done it?

See How to escape quote PHP strings generated by Delphi?
I am just interested to hear if anyone has used Delphi (or possibly BCB) as a code generator for PHP ...
(or thoughts about code generation from one language to another in general)
Hmm, any good books about code generation ?
I've generated javascript, SQL and Delphi many times. But mostly is basic substitution, (and the example in the post you mention looks the same), not really codegeneration in the "compiler" sense of the word.
But there are also many real compilers in Pascals and Delphi like dialects. The biggest one I think is Free Pascal (http://www.freepascal.org), which is a compiler for Object Pascal (aka delphi)
(added later:)
Besides variable substitution, basic templating engines also fall in this category. Templates are sometimes easier maintainable than the same fragement code. Specially in html/cgi land this is used a lot.
You can generate anything from a tool which can export text files no?
You can write all by the hand, or in a "delphi style" by using Delphi for PHP http://www.embarcadero.com/products/delphi-for-php
best regards,
anyone has used Delphi (or possibly BCB) as a code generator for PHP
PHP - no, but I'm generating a lot of Delphi/Pascal code from Delphi. I've also generated all other things used for a web application: HTML, JavaScript, CSS - but never PHP because I didn't need that. So it's possible, but simply knowing it's possible is not going to help you much.
thoughts about code generation from one language to another in general
You need to look into "text template engines" for Delphi. I can't suggest any because I wrote my own (and I'm not planing on releasing my own under any license).

convert any language into PHP sourcecode

Update:
This question is a duplicate of Are there any programming languages targeting PHP, besides Haxe?
The answers given here appear to be disjoint from those given at the other node, so this question was not (yet) deleted. If possible, please merge the answers here into the other node.
Question:
Is there any such thing as a programming language (other than an esoteric language such as BrainF##$, or the languages PHP or VB) that you can "compile" into non-obfuscated PHP source code?
Rationale:
Swip wants to generate ordinary PHP code because it is so ubiquitous for the types of projects swip wants to do. Unfortunately swip would like to actually avoid writing PHP -- strange but true! Swip is crazy enough to want to generate PHP source code without having to type any PHP into Swip's editor.
Take a look at
http://github.com/juliend2/phlower
This project claims about itself:
phlower (pronounced flower) is a small ruby script that compiles the Awesome code (invented by MACournoyer for his book void://createyourproglang.com/ ) into PHP code.
This script is written in Ruby and it depends on the racc gem.
Wasabi compiles down to PHP, but you'll have to beg Joel Spolsky for a copy.
I don't know what swip is, but this is not really possible. There are tools to aid the programmer in doing this, but they will not run without deep human interaction and refactoring. What you want is a skilled programmer.
Edit
I think I misunderstood, you want a scripting language to script PHP? While php compiles to bytecode internally, it isn't like java or .net where you can use different languages to do it. What are you trying to accomplish?

translation algorithm

Recently I am working into the ability of translating a PHP web application from one language to another. Well, most of those I read involves having language files, then display the selected one like this:
en.lang.php:
<?php
$_TEXT = array();
$_TEXT['welcome'] = 'Welcome to My Application';
?>
fr.lang.php: // french (i translated that with Google =x)
<?php
$_TEXT = array();
$_TEXT['welcome'] = 'Bienvenue sur mon application Web';
?>
I would like to ask if there's any better workflow or algorithm than this? Because value may be inserted into the text and so on - pretty hairy situation. Any help thanks!
Also to note that: this application must work cross-platform (or I should say platform-independent) as such no additional extensions are required based from PHP 4.4.2
I would advise using gettext, it'll make your life so much simpler...
The gettext functions implement an NLS
(Native Language Support) API which
can be used to internationalize your
PHP applications. Please see the
gettext documentation for your system
for a thorough explanation of these
functions or view the docs at ยป
http://www.gnu.org/software/gettext/manual/gettext.html.
Checkout PHP's gettext: http://www.php.net/manual/en/intro.gettext.php
If you want to roll your own simple solution, I define a function, __($native, $var1, $var2, ...), that takes the native string and performs the translation + variable substitution for you. The actual implementation of __ (two underscores) will depend on you, but typically $native is the key in your array above and it uses sprintf to substitute.
That s actually called Internationalization or localization.
If you are using php, i d recommend you to use smarty. You can do the same thing as you do with Java. and smarty has gettext plugin. you actually dont even have to mess with gettext, you can do it way easier than that.
http://www.smarty.net/
or perhaps you can check out the pear libraries i ve seen packages for localization.
http://pear.php.net/packages.php?catpid=28
gettext, as suggested by several fellow SOers is an excellent solution. It's not php specific, it's quite popular and as such several tools to simplify translation are available.
And last but not least, keeping the text in your default language in the source is many times easier to work with than having to remember the constant values for texts.

Parsing PHP/JavaScript document structure in Delphi

I need to parse PHP & JavaScript documents structure to get the info about document functions & their parameters, classes & their methods, variables, and so on ...
I'm wondering if there is any solution for doing that (no regular expressions) ... I've heard about something called "lexing" however I was unable to find any examples even the ones that could me tell if this is something what I am looking for or not ...
thanks in advance
By "Lexing" your referring to Lexical Analysis, and there are some ancient tools which mostly still work named Lex and Yacc. Lex builds the tokenizer, and Yacc stands for "yet another compiler compiler" and is the actual parser.
The concept of lex/Yacc, is you build a grammar for the language, and then run the grammar through the paslex tool to generate source code (normally in C) that you can use to parse a file and take action on specific keywords and tokens. Martin Waldenburg wrote a pascal version of lex/yacc named PasLex which has been kicking around for way over a decade now and has been converted to Delphi (although it might not work with the latest versions without some minor work). If I remember correctly, it uses the same .L grammar input files as lex, so any documentation you find for lex/yacc can also be applied to paslex, with the exception that you get pascal code as the output.
I'm not sure about current documentation availability. Before the internet (gasp) we used books and most of this was heavily documented on paper which has long turned yellow...however, rumor has it that you might..just might be able to pick up a used copy from Amazon. I cut my teeth on this using a book which is also known as "the dragon book" which appears to have been re-published as recently as 2006.
EDIT:
I was mistaken by the tool, it was TPLY. PasLex was a delphi grammar implementation...TPLY was the Lex/Yacc tool which generated pascal source from a .L file.
I'm not sure if this is feasible but for PHP would you be able to invoke the PHP CLI from Delphi to get the information?
If so you could call token_get_all() and then spit out the result in something that you can parse in Delphi (maybe xml, json, etc.). This is lexing. The problem with this is that is only half the problem solved - you still have to understand each token in context to get the results you want.

What software can I use to auto generate class diagrams in PHP?

I have some source code and I would like to auto generate class diagrams in PHP.
What software can I use to do this?
Duplicate
PHP UML Generator
UML tool for php
Doxygen can do class diagrams, too (if what I'm thinking of are "class diagrams" :) ).
Umbrello can do it.
Hava a look at Instant Reverse
This answer is for people who visits stackoverflow for finding answers to their queries.
http://pear.php.net/package/PHP_UML/
I have not evaluated PHP UML package thoroughly, but It should satisfy the need of small to medium size project.

Categories